From: Alexandru Gagniuc Date: Mon, 17 Dec 2012 08:04:35 +0000 (-0600) Subject: chronovu-la8: Fix memory leak in hw_scan X-Git-Tag: dsupstream~433 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=4f9bf9a202d331b0f2ec088d73d72808e1a934b4;p=libsigrok.git chronovu-la8: Fix memory leak in hw_scan Hardware scanning creates an ftdi_context before attempting to locate devices based on PID/VID. If no devices are detected, execution jumps to cleanup. The context is freed with free(), instead of ftdi_free(). We cannot assume that the libftdi context is stored in a contiguous memory region, and thus cannot use a simple free. Case in point, this situation is identified by valgrind as a "definitely lost" memory leak. Use ftdi_free() instead of a simple free() in hw_scan(). Valgrind no longer complains about a memory leak in this area. clear_instances() does not need any modification, as it correctly uses ftdi_free(). Signed-off-by: Alexandru Gagniuc --- diff --git a/hardware/chronovu-la8/api.c b/hardware/chronovu-la8/api.c index 9a512f90..c7a5ba83 100644 --- a/hardware/chronovu-la8/api.c +++ b/hardware/chronovu-la8/api.c @@ -179,7 +179,7 @@ static GSList *hw_scan(GSList *options) err_close_ftdic: (void) la8_close(devc); /* Log, but ignore errors. */ err_free_ftdic: - free(devc->ftdic); /* NOT g_free()! */ + ftdi_free(devc->ftdic); /* NOT free() or g_free()! */ err_free_final_buf: g_free(devc->final_buf); err_free_devc: