From: William Bourque Date: Mon, 19 Apr 2010 22:33:46 +0000 (-0400) Subject: Changed freeHandle() to test for empty before calling free X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=0ab8f4ef603497659971e1dd9f17f6aa37bec79f;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;