Possible leak of the devices buffer in doInquire() on every inquiry
I found a possible native memory leak in doInquire(). It allocates the devices
array with malloc and returns it by value, but neither caller ever frees it.
File: src/linux/DeviceINQ.cc
Function: DeviceINQ::doInquire (consumed by DeviceINQ::InquireSync and
InquireWorker::HandleOKCallback)
inquiryResult.devices = (bt_device*)malloc(num_rsp * sizeof(bt_device));
...
free( ii ); // the ii buffer is freed
close( sock );
return inquiryResult; // inquiryResult.devices is never freed
doInquire() returns inquiryResult by value with a heap devices array. Both callers
read inquiryResult.devices[i] in a loop and then discard the struct without ever
calling free(inquiryResult.devices). Every device scan (inquire() / inquireSync())
leaks the whole array (num_rsp * sizeof(bt_device)). The adjacent ii buffer is
freed, which makes the omission clear.
Suggested fix: free(inquiryResult.devices) in both callers after they finish consuming
it (or have doInquire return ownership through a type that frees it).
Possible leak of the
devicesbuffer indoInquire()on every inquiryI found a possible native memory leak in
doInquire(). It allocates thedevicesarray with
mallocand returns it by value, but neither caller ever frees it.File:
src/linux/DeviceINQ.ccFunction:
DeviceINQ::doInquire(consumed byDeviceINQ::InquireSyncandInquireWorker::HandleOKCallback)doInquire()returnsinquiryResultby value with a heapdevicesarray. Both callersread
inquiryResult.devices[i]in a loop and then discard the struct without evercalling
free(inquiryResult.devices). Every device scan (inquire()/inquireSync())leaks the whole array (
num_rsp * sizeof(bt_device)). The adjacentiibuffer isfreed, which makes the omission clear.
Suggested fix:
free(inquiryResult.devices)in both callers after they finish consumingit (or have
doInquirereturn ownership through a type that frees it).