]> granicus.if.org Git - sudo/commitdiff
Rename gc_cleanup to gc_run and remove I/O plugins from the plugin
authorTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 28 Jan 2016 21:48:11 +0000 (14:48 -0700)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 28 Jan 2016 21:48:11 +0000 (14:48 -0700)
list when freeing them.

src/sudo.c

index b7ab01b8d2ed4bdc12395f90688aa771cbd2d271..ed823c6e00b43b321ab6c7c9f9ffdfde1bbf21c8 100644 (file)
@@ -1484,6 +1484,9 @@ gc_add(enum sudo_gc_types type, void *v)
     struct sudo_gc_entry *gc;
     debug_decl(gc_add, SUDO_DEBUG_MAIN)
 
+    if (v == NULL)
+       debug_return_bool(false);
+
     gc = calloc(1, sizeof(*gc));
     if (gc == NULL) {
        sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
@@ -1509,18 +1512,18 @@ gc_add(enum sudo_gc_types type, void *v)
 #endif /* NO_LEAKS */
 }
 
+#ifdef NO_LEAKS
 static void
-gc_cleanup(void)
+gc_run(void)
 {
-#ifdef NO_LEAKS
     struct plugin_container *plugin;
     struct sudo_gc_entry *gc;
-    void *next;
     char **cur;
-    debug_decl(gc_cleanup, SUDO_DEBUG_MAIN)
+    debug_decl(gc_run, SUDO_DEBUG_MAIN)
 
     /* Collect garbage. */
-    SLIST_FOREACH_SAFE(gc, &sudo_gc_list, entries, next) {
+    while ((gc = SLIST_FIRST(&sudo_gc_list))) {
+       SLIST_REMOVE_HEAD(&sudo_gc_list, entries);
        switch (gc->type) {
        case GC_PTR:
            free(gc->u.ptr);
@@ -1539,19 +1542,20 @@ gc_cleanup(void)
 
     /* Free plugin structs. */
     free(policy_plugin.path);
-    TAILQ_FOREACH_SAFE(plugin, &io_plugins, entries, next) {
+    while ((plugin = TAILQ_FIRST(&io_plugins))) {
+       TAILQ_REMOVE(&io_plugins, plugin, entries);
        free(plugin->path);
        free(plugin);
     }
 
     debug_return;
-#endif /* NO_LEAKS */
 }
+#endif /* NO_LEAKS */
 
 static void
 gc_init(void)
 {
 #ifdef NO_LEAKS
-    atexit(gc_cleanup);
+    atexit(gc_run);
 #endif
 }