From db5504f973efded14c592f5404cce39c9b566329 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Fri, 30 Nov 2018 15:55:33 -0500 Subject: [PATCH] lib: plugin: reset pointers to `NULL` on destruction When an object's member is destroyed, internally, reset its pointer to `NULL` immediately. This makes it possible to log partial objects during destruction while keeping Valgrind's memcheck happy. Signed-off-by: Philippe Proulx --- include/babeltrace/plugin/plugin-internal.h | 9 +++++++++ lib/plugin/plugin-so.c | 3 +++ 2 files changed, 12 insertions(+) diff --git a/include/babeltrace/plugin/plugin-internal.h b/include/babeltrace/plugin/plugin-internal.h index 71977a74..de1035c7 100644 --- a/include/babeltrace/plugin/plugin-internal.h +++ b/include/babeltrace/plugin/plugin-internal.h @@ -127,40 +127,49 @@ void bt_plugin_destroy(struct bt_object *obj) if (plugin->src_comp_classes) { BT_LOGD_STR("Putting source component classes."); g_ptr_array_free(plugin->src_comp_classes, TRUE); + plugin->src_comp_classes = NULL; } if (plugin->flt_comp_classes) { BT_LOGD_STR("Putting filter component classes."); g_ptr_array_free(plugin->flt_comp_classes, TRUE); + plugin->flt_comp_classes = NULL; } if (plugin->sink_comp_classes) { BT_LOGD_STR("Putting sink component classes."); g_ptr_array_free(plugin->sink_comp_classes, TRUE); + plugin->sink_comp_classes = NULL; } if (plugin->info.name) { g_string_free(plugin->info.name, TRUE); + plugin->info.name = NULL; } if (plugin->info.path) { g_string_free(plugin->info.path, TRUE); + plugin->info.path = NULL; } if (plugin->info.description) { g_string_free(plugin->info.description, TRUE); + plugin->info.description = NULL; } if (plugin->info.author) { g_string_free(plugin->info.author, TRUE); + plugin->info.author = NULL; } if (plugin->info.license) { g_string_free(plugin->info.license, TRUE); + plugin->info.license = NULL; } if (plugin->info.version.extra) { g_string_free(plugin->info.version.extra, TRUE); + plugin->info.version.extra = NULL; } g_free(plugin); diff --git a/lib/plugin/plugin-so.c b/lib/plugin/plugin-so.c index b875ad68..357a4ccd 100644 --- a/lib/plugin/plugin-so.c +++ b/lib/plugin/plugin-so.c @@ -148,6 +148,8 @@ void bt_plugin_so_shared_lib_handle_destroy(struct bt_object *obj) BT_LOGE("Cannot close GModule: %s: path=\"%s\"", g_module_error(), path); } + + shared_lib_handle->module = NULL; #ifndef NDEBUG } else { BT_LOGD("Not closing GModule because `BABELTRACE_NO_DLCLOSE=1`: " @@ -158,6 +160,7 @@ void bt_plugin_so_shared_lib_handle_destroy(struct bt_object *obj) if (shared_lib_handle->path) { g_string_free(shared_lib_handle->path, TRUE); + shared_lib_handle->path = NULL; } g_free(shared_lib_handle); -- 2.34.1