discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss-gnuradio] memory leakage in usrp2::eth_buffer


From: Gaetano Mendola
Subject: [Discuss-gnuradio] memory leakage in usrp2::eth_buffer
Date: Wed, 9 Mar 2011 19:35:36 +0100

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]