From be3792c5c58cf5b79666d95140f39108c36fb230 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 17 Aug 2012 11:04:41 +0530 Subject: [PATCH] ... --- .../devices/mtp/windows/content_enumeration.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/calibre/devices/mtp/windows/content_enumeration.cpp b/src/calibre/devices/mtp/windows/content_enumeration.cpp index 859b6c9efa..56150bff85 100644 --- a/src/calibre/devices/mtp/windows/content_enumeration.cpp +++ b/src/calibre/devices/mtp/windows/content_enumeration.cpp @@ -179,7 +179,7 @@ public: }; static PyObject* bulk_get_filesystem(IPortableDevice *device, IPortableDevicePropertiesBulk *bulk_properties, const wchar_t *storage_id, IPortableDevicePropVariantCollection *object_ids) { - PyObject *folders = NULL, *ret = NULL; + PyObject *folders = NULL; GUID guid_context = GUID_NULL; HANDLE ev = NULL; IPortableDeviceKeyCollection *properties; @@ -230,22 +230,16 @@ static PyObject* bulk_get_filesystem(IPortableDevice *device, IPortableDevicePro } PyEval_RestoreThread(callback->thread_state); if (!ok) { - // We deliberately leak the callback object to prevent any crashes in case COM tries to call methods on it during a future pump_waiting_messages() - PyDict_Clear(folders); - folders = NULL; - callback = NULL; - ev = NULL; + bulk_properties->Cancel(guid_context); + pump_waiting_messages(); + Py_DECREF(folders); folders = NULL; } end: - if (folders != NULL) { - ret = PyDict_Values(folders); - Py_DECREF(folders); - } if (ev != NULL) CloseHandle(ev); if (properties != NULL) properties->Release(); if (callback != NULL) callback->Release(); - return ret; + return folders; } static BOOL find_all_objects_in(IPortableDeviceContent *content, IPortableDevicePropVariantCollection *object_ids, const wchar_t *parent_id) {