Libjack memory leak ?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Libjack memory leak ?

Fons Adriaensen-2
Trying to find out the origin of a memory leak in one of my apps
it turned out to be libjack.

Repeatedly registering and unregistering ports makes memory use
increase in chunks of 132K.

--
FA

Follie! Follie! Delirio vano è questo !



-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Jackit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jackit-devel
Reply | Threaded
Open this post in threaded view
|

Re: Libjack memory leak ?

Stéphane Letz

Le 2 mai 07 à 16:40, Fons Adriaensen a écrit :

> Trying to find out the origin of a memory leak in one of my apps
> it turned out to be libjack.
>
> Repeatedly registering and unregistering ports makes memory use
> increase in chunks of 132K.
>
> --  
> FA
>
> Follie! Follie! Delirio vano è questo !
>


In jackd the port memory structure allocated in libjack is not  
desallocated until the client itself is desallocated. I think the  
following version of  jack_port_unregister in port.c should solve the  
problem:

int
jack_port_unregister (jack_client_t *client, jack_port_t *port)
{
        jack_request_t req;
        JSList *node;
       
        for (node = client->ports; node; node = jack_slist_next (node)) {
                if (port == node->data) { /* found port */
                       
                        req.type = UnRegisterPort;
                        req.x.port_info.port_id = port->shared->id;
                        req.x.port_info.client_id = client->control->id;
       
                        int res = jack_client_deliver_request (client, &req);
                        if (res == 0) {
                                client->ports = jack_slist_remove (client->ports, port);
                                free (port);
                        }
                        return res;
                }
        }
        jack_error ("unregistering a port %x that is not own by the client",  
port);
        return -1;
}


Stephane
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Jackit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jackit-devel
Reply | Threaded
Open this post in threaded view
|

Re: Libjack memory leak ?

Fons Adriaensen-2
On Wed, May 02, 2007 at 04:47:16PM +0200, Stéphane Letz wrote:

>
> Le 2 mai 07 à 16:40, Fons Adriaensen a écrit :
>
> > Trying to find out the origin of a memory leak in one of my apps
> > it turned out to be libjack.
> >
> > Repeatedly registering and unregistering ports makes memory use
> > increase in chunks of 132K.
> >
> > --  
> > FA
> >
> > Follie! Follie! Delirio vano è questo !
> >
>
>
> In jackd the port memory structure allocated in libjack is not  
> desallocated until the client itself is desallocated. I think the  
> following version of  jack_port_unregister in port.c should solve the  
> problem:

Thanks, I'll try this out later today.

Reading the code in libjack/port.c raises many questions.

First, the only good reason I can see for not deallocating the port
struct would be that it can then be re-used. But this doesn't seem
to happen...

Second, I've been trying to understand the logic of the two versions
of jack_port_by_id() and jack_port_by_name() and the ports_ext list,
why sometime copies seem to be made, etc. but it doesn't make any
sense to me. Can you explain this ?


--
FA

Follie! Follie! Delirio vano è questo !



-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Jackit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jackit-devel
Reply | Threaded
Open this post in threaded view
|

Re: Libjack memory leak ?

Stéphane Letz

Le 2 mai 07 à 17:26, Fons Adriaensen a écrit :

> On Wed, May 02, 2007 at 04:47:16PM +0200, Stéphane Letz wrote:
>>
>> Le 2 mai 07 à 16:40, Fons Adriaensen a écrit :
>>
>>> Trying to find out the origin of a memory leak in one of my apps
>>> it turned out to be libjack.
>>>
>>> Repeatedly registering and unregistering ports makes memory use
>>> increase in chunks of 132K.
>>>
>>> --  
>>> FA
>>>
>>> Follie! Follie! Delirio vano è questo !
>>>
>>
>>
>> In jackd the port memory structure allocated in libjack is not
>> desallocated until the client itself is desallocated. I think the
>> following version of  jack_port_unregister in port.c should solve the
>> problem:
>
> Thanks, I'll try this out later today.
>
> Reading the code in libjack/port.c raises many questions.
>
> First, the only good reason I can see for not deallocating the port
> struct would be that it can then be re-used. But this doesn't seem
> to happen...
>
> Second, I've been trying to understand the logic of the two versions
> of jack_port_by_id() and jack_port_by_name() and the ports_ext list,
> why sometime copies seem to be made, etc. but it doesn't make any
> sense to me. Can you explain this ?
>


There was previously a ressource leak in jack_port_by_name and  
jack_port_by_id: both functions were *always* returning a newly  
allocated port struct, But the returned jack_port_t* was never  
desallocated. The point is that nobody ever knows when this  
jack_port_t* can be safely desallocated. jack_port_t* allocated with  
jack_port_register are supposed to be "desallocated" by  
jack_port_unregister, but the situation is less clear with  
jack_port_by_name and jack_port_by_id.  The ports_ext list maintains  
jack_port_t* pointer so that they are desallocated *at least* when  
the client is closed.

I think the design of the jack_port_by_name and jack_port_by_id  
functions is a bit problematic... Note that this ressource leak  
cannot happens in jackdmp when there is no jack_port_t struct anymore  
on the client side. The jack_port_t* actually is an index in the  
global shared memory port array.

Stephane
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Jackit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jackit-devel
Reply | Threaded
Open this post in threaded view
|

Re: Libjack memory leak ?

Grzegorz Jaśkiewicz
valgrind it!
--
GJ

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Jackit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jackit-devel