Closed hcw70 closed 4 years ago
Fixed and thank you!
Ohh, that was quicker than i can submit a MR!!!!
However you should re-init the data ptr to nullptr prior to the call to gp_camera_wait_for_event() since it is not assured that the data pointer is changed to nullptr in the call.
Else you get a crash due to double-free.
I would do it like:
void GPhotoCameraWorker::waitForOperationCompleted()
{
CameraEventType type;
int ret;
do {
void *data=nullptr;
ret = gp_camera_wait_for_event(m_camera, 10, &type, &data, m_context);
if (data)
free(data);
} while ((ret == GP_OK) && (type != GP_EVENT_TIMEOUT));
}
As can be seen in the implementation source of
gp_camera_wait_for_event()
and also in the comment from http://gphoto-software.10949.n7.nabble.com/Releasing-eventdata-from-gp-camera-wait-for-event-td14261.html the caller must free the event data viafree()
.If not doing this, memory is leaked on every call...