[OpenSIPS-Devel] [ opensips-Patches-3599314 ] Make perlvdb work with alias_db and without leaks

SourceForge.net noreply at sourceforge.net
Thu Jan 17 11:05:41 CET 2013


Patches item #3599314, was opened at 2013-01-03 04:39
Message generated for change (Comment added) made by bogdan_iancu
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=1086412&aid=3599314&group_id=232389

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: modules
Group: trunk
Status: Open
Resolution: Accepted
Priority: 5
Private: No
Submitted By: bratner (ratner2)
Assigned to: Bogdan-Andrei Iancu (bogdan_iancu)
Summary: Make perlvdb work with alias_db and without leaks

Initial Comment:
Several fixes:
1. change the the declared module name to db_perlvdb. Otherwise it is not found as db_ module. 
2. change the init db url type to actually be str
3. many changes that fix various memory leaks (perl object leaks)
4. fix result cleanup memory leaks

What works: Probably anything that does only query.
I use it for alias_db like this:
in opensips.cfg#perl stuff
loadmodule "perl.so"
modparam("perl", "modpath", "/usr/lib/opensips/perl")
modparam("perl", "filename", "/usr/lib/opensips/perl/vdbtest.pm")
loadmodule "perlvdb.so"

#alias lookup module 
loadmodule "alias_db.so"
modparam("alias_db", "db_url", "perlvdb:OpenSIPS::VDB::Adapter::Alias")
...
...
alias_db_lookup("OpenSIPS::VDB::VTab::MyCode","d" );  # Lookup the new user at domain for the incoming RURI
....

in /usr/lib/opensips/perl/vdbtest.pm:

use OpenSIPS::VDB::Adapter::Alias;
use OpenSIPS::VDB::VTab::MyCode;
use OpenSIPS;
1;

in /usr/lib/opensips/perl/OpenSIPS/VDB/VTab/MyCode.pm:

package OpenSIPS::VDB::VTab::MyCode;
@ISA = qw ( OpenSIPS::VDB::VTab OpenSIPS::Utils::Debug );
use OpenSIPS;
sub init {
        OpenSIPS::log(L_NOTICE, "Init in MyCode");
}



sub query {
        OpenSIPS::log(L_NOTICE, "Query in MyCode");
        my $self = shift;
        my $alias_username = shift;
        my $alias_domain = shift;
        OpenSIPS::log(L_NOTICE, "Finishing up the query in CP");
        return { username => "newuser", domain => "newdomain" };

}


1;


Any comments, bugs, requests to ratner2 at gmail.com





----------------------------------------------------------------------

>Comment By: Bogdan-Andrei Iancu (bogdan_iancu)
Date: 2013-01-17 02:05

Message:
There is problem in reverting the change I did : parseurl() accepts as
param  a null terminated string, while url->s (the param you pass to it) is
not a null terminated string - it is a string with len. So, this may leas
to mem overflow.

What I did in the prev patch is to make a copy of the url->s into a
different buffer to make it null terminated.

I reworked the code to work all the time with a STR instead of CHAR* ->
please see commit 9563 .

Thanks and regards,

----------------------------------------------------------------------

Comment By: bratner (ratner2)
Date: 2013-01-16 06:59

Message:
There is a problem with the merged pervdb_init(). db_perlvdb uses the
db_con_t to store only one thing - the reference to a perl object reference
in the 'tail' hook. thus the module allocates sizeof(db_con_t)+sizeof(SV)
and sets only tail. 
In any case i add a patch to fix latest trunk. 

Another thing i missed is that Constants.pm is outdated. DB_BIGINT to was
added in db_val.h and now perl db type ids are off by 1. the patch i added
fixes this too. 

----------------------------------------------------------------------

Comment By: Bogdan-Andrei Iancu (bogdan_iancu)
Date: 2013-01-15 10:06

Message:
module name also changed - an overall testing would be appreciated. 

----------------------------------------------------------------------

Comment By: Bogdan-Andrei Iancu (bogdan_iancu)
Date: 2013-01-15 08:29

Message:
BTW, please test my change in db init and confirm if ok

----------------------------------------------------------------------

Comment By: Bogdan-Andrei Iancu (bogdan_iancu)
Date: 2013-01-15 08:29

Message:
I uploaded the patch to trunk only (it may need more testing before moving
to stable 1.8). I had to change the init db function as the change char ->
str was not correct - the processing inside the function was still
expecting a CHAR (nul terminated) -> this may have lead to memory
overflow.

I will also rename the whole module to db_perlvdb

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=1086412&aid=3599314&group_id=232389



More information about the Devel mailing list