[dpkg] 73/187: dpkg: Switch from non-freeing malloc to m_malloc for invoke hooks

Reiner Herrmann reiner at reiner-h.de
Sun Nov 6 12:46:26 UTC 2016


This is an automated email from the git hooks/post-receive script.

deki-guest pushed a commit to branch master
in repository dpkg.

commit 4cf0771c7e06bbb0bdfd0ff041672e462a122605
Author: Guillem Jover <guillem at debian.org>
Date:   Wed Aug 17 02:41:59 2016 +0200

    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.
---
 debian/changelog |  1 +
 src/main.c       | 19 +++++++++++++++++--
 src/main.h       |  2 +-
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 96373ec..da763d2 100644
--- a/debian/changelog
+++ b/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
diff --git a/src/main.c b/src/main.c
index ccf2777..4a721b8 100644
--- a/src/main.c
+++ b/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);
diff --git a/src/main.h b/src/main.h
index 15ee278..fc083a9 100644
--- a/src/main.h
+++ b/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 {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git



More information about the Reproducible-commits mailing list