Explorar o código

dpkg: Switch from non-freeing malloc to m_malloc for invoke hooks

These do not need to be part of the non-freeing memory pool, as that
should be reserved for packaging metadata.
Guillem Jover %!s(int64=10) %!d(string=hai) anos
pai
achega
4cf0771c7e
Modificáronse 3 ficheiros con 19 adicións e 3 borrados
  1. 1 0
      debian/changelog
  2. 17 2
      src/main.c
  3. 1 1
      src/main.h

+ 1 - 0
debian/changelog

@@ -18,6 +18,7 @@ dpkg (1.18.11) UNRELEASED; urgency=medium
   * Generate reproducible file modes for the .deb control member contents.
     Closes: #787980
   * Switch from non-freeing malloc to m_malloc on statdb slurping.
+  * Switch from non-freeing malloc to m_malloc for invoke hooks.
   * Perl modules:
     - Obsolete Source-Version substvar in Dpkg::Substvars by emitting errors.
     - Rework keyring hooks in Dpkg::Vendor. Deprecate the keyrings hook, and

+ 17 - 2
src/main.c

@@ -439,8 +439,8 @@ set_invoke_hook(const struct cmdinfo *cip, const char *value)
   struct invoke_list *hook_list = cip->arg_ptr;
   struct invoke_hook *hook_new;
 
-  hook_new = nfmalloc(sizeof(struct invoke_hook));
-  hook_new->command = nfstrsave(value);
+  hook_new = m_malloc(sizeof(struct invoke_hook));
+  hook_new->command = m_strdup(value);
   hook_new->next = NULL;
 
   /* Add the new hook at the tail of the list to preserve the order. */
@@ -469,6 +469,18 @@ run_invoke_hooks(const char *action, struct invoke_list *hook_list)
   unsetenv("DPKG_HOOK_ACTION");
 }
 
+static void
+free_invoke_hooks(struct invoke_list *hook_list)
+{
+  struct invoke_hook *hook, *hook_next;
+
+  for (hook = hook_list->head; hook; hook = hook_next) {
+    hook_next = hook->next;
+    free(hook->command);
+    free(hook);
+  }
+}
+
 static int
 run_logger(struct invoke_hook *hook, const char *name)
 {
@@ -902,6 +914,9 @@ int main(int argc, const char *const *argv) {
   if (is_invoke_action(cipaction->arg_int))
     run_invoke_hooks(cipaction->olong, &post_invoke_hooks);
 
+  free_invoke_hooks(&pre_invoke_hooks);
+  free_invoke_hooks(&post_invoke_hooks);
+
   dpkg_program_done();
 
   return reportbroken_retexitstatus(ret);

+ 1 - 1
src/main.h

@@ -149,7 +149,7 @@ extern struct pkg_list *ignoredependss;
 
 struct invoke_hook {
 	struct invoke_hook *next;
-	const char *command;
+	char *command;
 };
 
 struct invoke_list {