lib: plugin: reset pointers to `NULL` on destruction
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 30 Nov 2018 20:55:33 +0000 (15:55 -0500)
committerFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 2 May 2019 20:50:15 +0000 (20:50 +0000)
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 <eeppeliteloop@gmail.com>
include/babeltrace/plugin/plugin-internal.h
lib/plugin/plugin-so.c

index 71977a747465a5e381da469a3a65e92be3703b00..de1035c76f14ca6eaf9aa202c0e19856a4eb665e 100644 (file)
@@ -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);
index b875ad68953598b5a2217977e96725d3e136d54f..357a4ccd6feffa911007366fb7755fcecd148e7b 100644 (file)
@@ -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);
This page took 0.0262 seconds and 4 git commands to generate.