From 6775cc444ea508b9bd8b68665de92cccc1dfb941 Mon Sep 17 00:00:00 2001 From: Marcus Meissner Date: Thu, 18 Jan 2007 19:11:50 +0000 Subject: [PATCH] free data structures on closing the camera. updated TODO git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@9899 67ed7778-7388-44ab-90cf-0a291f65f57c --- camlibs/ptp2/ChangeLog | 5 +++++ camlibs/ptp2/TODO | 6 ------ camlibs/ptp2/library.c | 39 +++++++++++++++++++++++---------------- camlibs/ptp2/ptp-pack.c | 14 ++++++++++++++ camlibs/ptp2/ptp.c | 27 +++++++++++++++++++++++++++ camlibs/ptp2/ptp.h | 2 ++ 6 files changed, 71 insertions(+), 22 deletions(-) diff --git a/camlibs/ptp2/ChangeLog b/camlibs/ptp2/ChangeLog index 3c129ed04..c7b8af495 100644 --- a/camlibs/ptp2/ChangeLog +++ b/camlibs/ptp2/ChangeLog @@ -1,3 +1,8 @@ +2007-01-18 Marcus Meissner + + * library.c, ptp.c, ptp-pack.c, ptp.h: + Free datastructures on closing the camera. + 2007-01-14 Marcus Meissner * usb.c: read in 64kb blobs again (512 bytes read are diff --git a/camlibs/ptp2/TODO b/camlibs/ptp2/TODO index 5fe3df18f..6af5cc95d 100644 --- a/camlibs/ptp2/TODO +++ b/camlibs/ptp2/TODO @@ -1,11 +1,5 @@ - Unordered TODO list: --- free() all malloced memory upon exit! - --- update params.handles and params.objectinfo structures after deletion of -folders/files - -- lot of internal error handling code is needed and the whole internal error reporting scheme has to be reorganized and improved! diff --git a/camlibs/ptp2/library.c b/camlibs/ptp2/library.c index 563200144..2037d2afe 100644 --- a/camlibs/ptp2/library.c +++ b/camlibs/ptp2/library.c @@ -1040,12 +1040,16 @@ static int camera_exit (Camera *camera, GPContext *context) { if (camera->pl!=NULL) { + PTPParams *params = &camera->pl->params; /* close iconv converters */ iconv_close(camera->pl->params.cd_ucs2_to_locale); iconv_close(camera->pl->params.cd_locale_to_ucs2); /* close ptp session */ - ptp_closesession (&camera->pl->params); - free (camera->pl); + ptp_closesession (params); + ptp_free_params(params); + free (params->data); + free (camera->pl); /* also frees params */ + params = NULL; camera->pl = NULL; } if (camera->port!=NULL) { @@ -1057,10 +1061,6 @@ camera_exit (Camera *camera, GPContext *context) gp_port_usb_clear_halt (camera->port, GP_PORT_USB_ENDPOINT_INT); } - - /* FIXME: free all camera->pl->params.objectinfo[] and - other malloced data, like wifi profiles */ - return (GP_OK); } @@ -2289,23 +2289,29 @@ folder_list_func (CameraFilesystem *fs, const char *folder, CameraList *list, if (ptp_operation_issupported(params,PTP_OC_GetStorageIDs)) { CPR (context, ptp_getstorageids(params, &storageids)); - } else { - storageids.n = 1; - storageids.Storage[0]=0xdeadbeef; - } - for (i=0; iSerialNumber) free (di->SerialNumber); + if (di->DeviceVersion) free (di->DeviceVersion); + if (di->Model) free (di->Model); + if (di->Manufacturer) free (di->Manufacturer); + if (di->ImageFormats) free (di->ImageFormats); + if (di->CaptureFormats) free (di->CaptureFormats); + if (di->VendorExtensionDesc) free (di->VendorExtensionDesc); + if (di->OperationsSupported) free (di->OperationsSupported); + if (di->EventsSupported) free (di->EventsSupported); + if (di->DevicePropertiesSupported) free (di->DevicePropertiesSupported); +} /* ObjectHandles array pack/unpack */ diff --git a/camlibs/ptp2/ptp.c b/camlibs/ptp2/ptp.c index 16a97d83c..9a5afa4c7 100644 --- a/camlibs/ptp2/ptp.c +++ b/camlibs/ptp2/ptp.c @@ -460,6 +460,33 @@ ptp_closesession (PTPParams* params) return ptp_transaction_new(params, &ptp, PTP_DP_NODATA, 0, NULL); } +/** + * ptp_free_params: + * params: PTPParams* + * + * Frees all data within the PTPParams struct. + * + * Return values: Some PTP_RC_* code. + **/ +void +ptp_free_params (PTPParams *params) { + while (params->proplist) { + MTPPropList *xpl = params->proplist; + + if ((xpl->datatype == PTP_DTC_STR) && (xpl->propval.str)) + free (xpl->propval.str); + params->proplist = xpl->next; + free (xpl); + } + if (params->canon_flags) free (params->canon_flags); + if (params->cameraname) free (params->cameraname); + if (params->wifi_profiles) free (params->wifi_profiles); + free (params->handles.Handler); + free (params->objectinfo); + ptp_free_DI (¶ms->deviceinfo); +} + + /** * ptp_getststorageids: * params: PTPParams* diff --git a/camlibs/ptp2/ptp.h b/camlibs/ptp2/ptp.h index 84e555040..dc1a63cfc 100644 --- a/camlibs/ptp2/ptp.h +++ b/camlibs/ptp2/ptp.h @@ -1536,6 +1536,8 @@ int ptp_property_issupported (PTPParams* params, uint16_t property); void ptp_free_devicepropdesc (PTPDevicePropDesc* dpd); void ptp_free_devicepropvalue (uint16_t dt, PTPPropertyValue* dpd); void ptp_free_objectpropdesc (PTPObjectPropDesc* dpd); +void ptp_free_params (PTPParams *params); + void ptp_perror (PTPParams* params, uint16_t error); const char*