liballeg/allegro5

Memory leak in MacOS joystick code

Closed this issue · 6 comments

The static analyzer tells me there's a leak here:

{
CFIndex num_devices = CFSetGetCount(devices);
IOHIDDeviceRef *device_arr = calloc(num_devices, sizeof(IOHIDDeviceRef));
CFSetGetValues(devices, (const void **) device_arr);
for (i = 0; i < num_devices; i++) {
IOHIDDeviceRef dev = device_arr[i];
add_joystick_device(dev, false);
num_joysticks_enumerated++;
}
CFRelease(devices);
}

device_arr is calloc'd and never freed.
Probably not a big deal as it's called only once by init_joystick

what static analyzer did you use?

The one in Xcode but I believe it's based on the same technology as the clang static analyzer (scan-build or whatever)

@ReiquelApplegate do you think it's wrong?

No, I agree free(device_arr) should be called.

Trivial really but I'll do a PR for this.
@SiegeLord should we be using al_calloc for internal memory allocation?

Vs a plain calloc, yes, most of the time.