]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Do lsan/valgrind checks once on init
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 1 Jul 2018 17:26:49 +0000 (13:26 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 1 Jul 2018 17:30:45 +0000 (13:30 -0400)
src/main/dl.c
src/main/unit_test_module.c

index 8174091e555f4aae5e8c99aecafa029634559cb0..824e98bc1021e99219acb9882c7ce25cc1ba7cc2 100644 (file)
@@ -111,6 +111,7 @@ typedef struct dl_loader {
 } dl_loader_t;
 
 static dl_loader_t *dl_loader;
+static bool do_dlclose = true; /* Sometimes we need to leave libraries loaded for debugging */
 
 /** Name prefixes matching the types of loadable module
  */
@@ -361,7 +362,7 @@ static int _dl_free(dl_t *module)
         *      Only dlclose() handle if we're *NOT* running under valgrind
         *      as it unloads the symbols valgrind needs.
         */
-       if (!RUNNING_ON_VALGRIND && (fr_get_lsan_state() != 1)) dlclose(module->handle);        /* ignore any errors */
+       if (do_dlclose) dlclose(module->handle);        /* ignore any errors */
 
        module->handle = NULL;
 
@@ -372,7 +373,10 @@ static int _dl_free(dl_t *module)
         *      dl *MUST* be set to NULL, so that if the server decides to
         *      load more modules, the tree is recreated.
         */
-       if (rbtree_num_elements(dl_loader->tree) == 0) TALLOC_FREE(dl_loader);
+       if (rbtree_num_elements(dl_loader->tree) == 0) {
+               ERROR("Freeing dl loader");
+               TALLOC_FREE(dl_loader);
+       }
 
        return 0;
 }
@@ -907,16 +911,16 @@ static int _dl_walk_print(UNUSED void *context, void *data)
 {
        dl_t *dl = talloc_get_type_abort(data, dl_t);
 
-       WARN("  %s", dl->name);
+       WARN("  %s (%zu)", dl->name, talloc_reference_count(dl));
 
        return 0;
 }
 
 static int _dl_inst_walk_print(UNUSED void *context, void *data)
 {
-       dl_instance_t *dl_instance = talloc_get_type_abort(data, dl_instance_t);
+       dl_instance_t *dl_inst = talloc_get_type_abort(data, dl_instance_t);
 
-       WARN("  %s", dl_instance->name);
+       WARN("  %s", dl_inst->name);
 
        return 0;
 }
@@ -964,7 +968,7 @@ int dl_loader_init(TALLOC_CTX *ctx, char const *lib_dir)
        if (!dl_loader->tree) {
                ERROR("Failed initialising dl->tree");
        error:
-               talloc_free(dl_loader);
+               TALLOC_FREE(dl_loader);
                return -1;
        }
 
@@ -994,5 +998,12 @@ int dl_loader_init(TALLOC_CTX *ctx, char const *lib_dir)
 
        talloc_set_destructor(dl_loader, _dl_loader_free);
 
+       /*
+        *      Run this now to avoid bizarre issues
+        *      with the talloc atexit handlers firing
+        *      in the child, and that causing issues.
+        */
+       do_dlclose = (!RUNNING_ON_VALGRIND && (fr_get_lsan_state() != 1));
+
        return 0;
 }
index 08aa53bfb8e45cd6287e51dec7523417db2da7ba..0d9b348da4fc6bb71d539835dc1df6dc31232b82 100644 (file)
@@ -1179,12 +1179,11 @@ finish:
         */
        xlat_unregister("poke");
 
-       ERROR("MODULES FREE");
        /*
         *      Detach modules, connection pools, registered xlats / paircmps / maps.
         */
        modules_free();
-       ERROR("MODULES DONE");
+
        /*
         *      The only paircmps remaining are the ones registered by the server core.
         */