dept2 / qtmultimedia-gphoto

Qt 5 Multimedia framework gphoto2 camera plugin
25 stars 11 forks source link

Memory leak in gp_camera_wait_for_event #6

Closed hcw70 closed 4 years ago

hcw70 commented 4 years ago

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 via free().

If not doing this, memory is leaked on every call...

cyberbobs commented 4 years ago

Fixed and thank you!

hcw70 commented 4 years ago

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.

hcw70 commented 4 years ago

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));
}