[Kamailio-Users] core:proxy.c problem

marius zbihlei marius.zbihlei at 1and1.ro
Tue Jan 26 17:02:58 CET 2010


Hello,

There seems to be a design problem in proxy.c mk_proxy(str* name, 
unsigned short port, unsigned short proto,
        int is_sips) function. The purpose of this function is to create 
a proxy and return a pointer to the
created structure.

The issue arises from the fact that the name (type struct str) member of 
the proxy structure is not deep copied from the given parameters(refer 
to the str* name ) (the hostent structure is instead deep copied). This 
isn't a problem for now but I have worked on a small patch that caches 
proxies (using add_proxy() and find_proxy()) and ,because of this 
shallow copy, things are broken.

I said that this is a design problem because we can let the shallow copy 
happen (performance is better), and when needed the caller should 
provide a buffer that doesn't change (let him do the copy instead). This 
is not clearly documented but done from /modules(_k)/utils/conf.c. But 
it this way we may have a memory leak when the proxy is deallocated, 
because I doubt that the caller keeps track of the allocated buffers(the 
code in proxy.c doesn't take ownership of the given pointer).

This affects functions mk_proxy and mk_shm_proxy in both kamailio(1.5 to 
speak of) and sip-router.

I have created a patch that also does a deep copy of the name, thus 
removing the need for the caller to bother about the lifetime of the 
name buffer.

Any ideas?!

Cheers
Marius




More information about the sr-users mailing list