[ofa-general] memory leak in librdmacm, libibverbs

Allen Hubbe ahubbe at iol.unh.edu
Thu Jun 14 10:56:43 PDT 2007


I found a memory leak that is present in at least librdmacm and
libibverbs.  The libraries allow a user to get a device list, and later
free the device list.  In freeing the device list, the devices in the list
are not freed, causing a memory leak.  It would not be wise to free all
the devices in the list, either, because the user very likely wants to
continue using one of the devices that was returned in the list.  I think
the intent of the methods was for the list to live the life of the
program, but that might not be the way it gets used.  I included a short
example program, run on a machine with devices present it will consume all
available memory.

---------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <rdma/rdma_cma.h>

int main(){

      struct ibv_context **ibv_devices;
      int num_devices;

      ibv_devices = rdma_get_devices(&num_devices);
      if(ibv_devices == NULL)
      {
          printf("no devices found, exiting\n");
          exit(1);
      }
      else
      {
          while(1)
          {
              rdma_free_devices(ibv_devices);
              ibv_devices = rdma_get_devices(NULL);
          }
      }

      return 0;
}
---------------------------------------------------------------



More information about the general mailing list