Panu Matilainen 293b44
From f78be76a00878183da86d5e37ddbe421c5fe028c Mon Sep 17 00:00:00 2001
Panu Matilainen 293b44
Message-Id: <f78be76a00878183da86d5e37ddbe421c5fe028c.1663150557.git.pmatilai@redhat.com>
Panu Matilainen 293b44
From: Panu Matilainen <pmatilai@redhat.com>
Panu Matilainen 293b44
Date: Wed, 14 Sep 2022 13:13:24 +0300
Panu Matilainen 293b44
Subject: [PATCH] Fix a memory leak in the new directory dance in ensureDir()
Panu Matilainen 293b44
Panu Matilainen 293b44
This would leak the path whenever we already had the directory open.
Panu Matilainen 293b44
Which happens a lot. Oops.
Panu Matilainen 293b44
---
Panu Matilainen 293b44
 lib/fsm.c | 5 +++--
Panu Matilainen 293b44
 1 file changed, 3 insertions(+), 2 deletions(-)
Panu Matilainen 293b44
Panu Matilainen 293b44
diff --git a/lib/fsm.c b/lib/fsm.c
Panu Matilainen 293b44
index 129054067..7987abbc9 100644
Panu Matilainen 293b44
--- a/lib/fsm.c
Panu Matilainen 293b44
+++ b/lib/fsm.c
Panu Matilainen 293b44
@@ -374,8 +374,6 @@ static int fsmDoMkDir(rpmPlugins plugins, int dirfd, const char *dn,
Panu Matilainen 293b44
 static int ensureDir(rpmPlugins plugins, const char *p, int owned, int create,
Panu Matilainen 293b44
 		    int quiet, int *dirfdp)
Panu Matilainen 293b44
 {
Panu Matilainen 293b44
-    char *path = xstrdup(p);
Panu Matilainen 293b44
-    char *dp = path;
Panu Matilainen 293b44
     char *sp = NULL, *bn;
Panu Matilainen 293b44
     char *apath = NULL;
Panu Matilainen 293b44
     int oflags = O_RDONLY;
Panu Matilainen 293b44
@@ -387,6 +385,9 @@ static int ensureDir(rpmPlugins plugins, const char *p, int owned, int create,
Panu Matilainen 293b44
     int dirfd = fsmOpenat(-1, "/", oflags, 1);
Panu Matilainen 293b44
     int fd = dirfd; /* special case of "/" */
Panu Matilainen 293b44
 
Panu Matilainen 293b44
+    char *path = xstrdup(p);
Panu Matilainen 293b44
+    char *dp = path;
Panu Matilainen 293b44
+
Panu Matilainen 293b44
     while ((bn = strtok_r(dp, "/", &sp)) != NULL) {
Panu Matilainen 293b44
 	fd = fsmOpenat(dirfd, bn, oflags, 1);
Panu Matilainen 293b44
 	/* assemble absolute path for plugins benefit, sigh */
Panu Matilainen 293b44
-- 
Panu Matilainen 293b44
2.37.3
Panu Matilainen 293b44