[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Discuss-gnuradio] Re: memory leakage in usrp2::eth_buffer
From: |
Gaetano Mendola |
Subject: |
Re: [Discuss-gnuradio] Re: memory leakage in usrp2::eth_buffer |
Date: |
Fri, 11 Mar 2011 10:28:06 +0100 |
Tom,
let me know when you have applied it.
On Thu, Mar 10, 2011 at 2:07 PM, Tom Rondeau <address@hidden> wrote:
> Thanks, Gaetano,
> I haven't looked at the code yet, but the patch looks right. Hopefully, I'll
> get it in tonight.
> Tom
>
> On Thu, Mar 10, 2011 at 6:15 AM, Gaetano Mendola <address@hidden> wrote:
>>
>> This is the patch:
>>
>> --- gnuradio-3.3.0/usrp2/host/lib/eth_buffer.cc 2010-06-01
>> 07:04:09.000000000 +0200
>> +++ gnuradio-3.3.0-fix/usrp2/host/lib/eth_buffer.cc 2011-03-10
>> 11:05:52.652353106 +0100
>> @@ -156,8 +156,14 @@
>> {
>> // if we have background thread, stop it here
>>
>> - if (!d_using_tpring && d_buf)
>> + if (!d_using_tpring && d_buf) {
>> free(d_buf);
>> + }
>> + else {
>> + if(d_buf) {
>> + munmap(d_buf, d_buflen);
>> + }
>> + }
>>
>> return d_ethernet->close();
>> }
>>
>>
>> On Wed, Mar 9, 2011 at 7:35 PM, Gaetano Mendola <address@hidden> wrote:
>> > Hi,
>> > in the method usrp2::eth_buffer::open in case the attempt to use the
>> > socket option PACKET_RX_RING
>> > fails an mmap is performed instead of a malloc.
>> >
>> > The method usrp2::eth_buffer::close however has to perform a munmap in
>> > order to let the
>> > kernel release the mapped memory, indeed only closing the file
>> > descriptor isn't enough.
>> >
>> > I suggest to change (inside the close method):
>> >
>> > if (!d_using_tpring && d_buf)
>> > free(d_buf);
>> >
>> > to:
>> >
>> >
>> > if (!d_using_tpring) {
>> > free(d_buf);
>> > } else {
>> > if (d_buf) munmap(d_buf, d_buflen);
>> > }
>> >
>> > note that there is no need to test for d_buf in case of free call
>> > indeed freeing a pointer to 0 is perfect valid code, the standard
>> > say that in case of free(NULL) no action is taken, to the other side
>> > munmap a NULL pointer is not permitted (hence the test).
>> >
>> > Regards
>> > Gaetano Mendola
>> >
>> > --
>> > cpp-today.blogspot.com
>> >
>>
>>
>>
>> --
>> cpp-today.blogspot.com
>>
>> _______________________________________________
>> Discuss-gnuradio mailing list
>> address@hidden
>> http://lists.gnu.org/mailman/listinfo/discuss-gnuradio
>
>
--
cpp-today.blogspot.com