From 9e9c19687d981a87e52e6df523b43b4a7526c142 Mon Sep 17 00:00:00 2001 From: Hyihong Chae Date: Wed, 19 Apr 2017 17:06:30 +0900 Subject: [PATCH] add free routine for svace issue. Change-Id: Iffe05fadb4b53d85922d8ad6537e59367560adae Signed-off-by: HyiHong Chae --- src/libusb1-glue.c | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/libusb1-glue.c b/src/libusb1-glue.c index 212edcd..fb0113d 100755 --- a/src/libusb1-glue.c +++ b/src/libusb1-glue.c @@ -914,8 +914,7 @@ ptp_read_func ( CONTEXT_BLOCK_SIZE, &xread, ptp_usb->timeout); - } - else { + } else { ret = USB_BULK_READ(ptp_usb->handle, ptp_usb->inep, bytes, @@ -946,8 +945,10 @@ ptp_read_func ( } int putfunc_ret = handler->putfunc(NULL, handler->priv, xread, bytes, &written); - if (putfunc_ret != PTP_RC_OK) + if (putfunc_ret != PTP_RC_OK) { + free(bytes); return putfunc_ret; + } ptp_usb->current_transfer_complete += xread; curread += xread; @@ -955,18 +956,19 @@ ptp_read_func ( // Increase counters, call callback if (ptp_usb->callback_active) { if (ptp_usb->current_transfer_complete >= ptp_usb->current_transfer_total) { - // send last update and disable callback. - ptp_usb->current_transfer_complete = ptp_usb->current_transfer_total; - ptp_usb->callback_active = 0; + // send last update and disable callback. + ptp_usb->current_transfer_complete = ptp_usb->current_transfer_total; + ptp_usb->callback_active = 0; } if (ptp_usb->current_transfer_callback != NULL) { - int ret; - ret = ptp_usb->current_transfer_callback(ptp_usb->current_transfer_complete, - ptp_usb->current_transfer_total, - ptp_usb->current_transfer_callback_data); - if (ret != 0) { - return PTP_ERROR_CANCEL; - } + int ret; + ret = ptp_usb->current_transfer_callback(ptp_usb->current_transfer_complete, + ptp_usb->current_transfer_total, + ptp_usb->current_transfer_callback_data); + if (ret != 0) { + free(bytes); + return PTP_ERROR_CANCEL; + } } } @@ -1046,7 +1048,7 @@ ptp_write_func ( LIBMTP_USB_DEBUG("USB OUT==>\n"); if (ret != LIBUSB_SUCCESS) { - free(bytes); + free(bytes); return PTP_ERROR_IO; } LIBMTP_USB_DATA(bytes+usbwritten, xwritten, 16); @@ -1059,19 +1061,19 @@ ptp_write_func ( // call callback if (ptp_usb->callback_active) { if (ptp_usb->current_transfer_complete >= ptp_usb->current_transfer_total) { - // send last update and disable callback. - ptp_usb->current_transfer_complete = ptp_usb->current_transfer_total; - ptp_usb->callback_active = 0; + // send last update and disable callback. + ptp_usb->current_transfer_complete = ptp_usb->current_transfer_total; + ptp_usb->callback_active = 0; } if (ptp_usb->current_transfer_callback != NULL) { - int ret; - ret = ptp_usb->current_transfer_callback(ptp_usb->current_transfer_complete, - ptp_usb->current_transfer_total, - ptp_usb->current_transfer_callback_data); - if (ret != 0) { + int ret; + ret = ptp_usb->current_transfer_callback(ptp_usb->current_transfer_complete, + ptp_usb->current_transfer_total, + ptp_usb->current_transfer_callback_data); + if (ret != 0) { free(bytes); - return PTP_ERROR_CANCEL; - } + return PTP_ERROR_CANCEL; + } } } if (xwritten < towrite) /* short writes happen */ -- 2.7.4