From: William Bourque Date: Mon, 19 Apr 2010 22:34:50 +0000 (-0400) Subject: Changed freeHandle() to test for empty before calling free X-Git-Tag: 0.12.32~14^2~1 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=f87369bbd73c812a940a0b3905f9bec9811355d2;p=lttv.git Changed freeHandle() to test for empty before calling free --- diff --git a/ltt/lttvtraceread_loader.c b/ltt/lttvtraceread_loader.c index e2f0da9b..6b519be5 100644 --- a/ltt/lttvtraceread_loader.c +++ b/ltt/lttvtraceread_loader.c @@ -138,17 +138,27 @@ JNIEXPORT void JNICALL Java_org_eclipse_linuxtools_lttng_jni_factory_JniTraceVer } void freeAllHandle() { - free(version_table); - free(version_functions_table); + if ( version_table != NULL ) { + free(version_table); + version_table = NULL; + } + + if ( version_functions_table != NULL ) { + free(version_functions_table); + version_functions_table = NULL; + } } void freeHandle(int handle_id) { - if (version_table[handle_id].static_handle != NULL) { - /* Memory will be freed by dlclose as well */ - dlclose(version_table[handle_id].static_handle); - version_table[handle_id].static_handle = NULL; - free(version_table[handle_id].libname); - version_table[handle_id].libname = NULL; + + if ( handle_id >= nb_id ) { + if (version_table[handle_id].static_handle != NULL) { + /* Memory will be freed by dlclose as well */ + dlclose(version_table[handle_id].static_handle); + version_table[handle_id].static_handle = NULL; + free(version_table[handle_id].libname); + version_table[handle_id].libname = NULL; + } } int isEmpty = 1;