From: Gerhard Sittig Date: Sun, 26 Mar 2017 13:46:37 +0000 (+0200) Subject: backend: fixup resource leak in sr_init() error code path X-Git-Url: http://sigrok.org/gitweb/?a=commitdiff_plain;h=928560e6f52f1287155ae8deb9e97e5607ec98db;p=libsigrok.git backend: fixup resource leak in sr_init() error code path Early sr_init() steps can just 'return' fine. After allocation of the 'context' memory, make all error paths 'goto done' before returning, to undo the memory allocation. --- diff --git a/src/backend.c b/src/backend.c index e5fe6a3f..a88459ac 100644 --- a/src/backend.c +++ b/src/backend.c @@ -540,22 +540,22 @@ SR_API int sr_init(struct sr_context **ctx) if (sanity_check_all_drivers(context) < 0) { sr_err("Internal driver error(s), aborting."); - return ret; + goto done; } if (sanity_check_all_input_modules() < 0) { sr_err("Internal input module error(s), aborting."); - return ret; + goto done; } if (sanity_check_all_output_modules() < 0) { sr_err("Internal output module error(s), aborting."); - return ret; + goto done; } if (sanity_check_all_transform_modules() < 0) { sr_err("Internal transform module error(s), aborting."); - return ret; + goto done; } #ifdef _WIN32 @@ -580,9 +580,7 @@ SR_API int sr_init(struct sr_context **ctx) context = NULL; ret = SR_OK; -#if defined(HAVE_LIBUSB_1_0) || defined(_WIN32) done: -#endif g_free(context); return ret; }