Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
libpkg: Avoid an unnecessary memory allocation in mkdirat_p()
Mark Johnston committed 7 months ago
commit 236719c2d230500cedc8c9306d3c3c014293e4f8
parent 9c026f3
1 file changed +3 -5
modified libpkg/utils.c
@@ -833,11 +833,11 @@ bool
mkdirat_p(int fd, const char *path)
{
	const char *next;
-
	char *walk, *walkorig, pathdone[MAXPATHLEN];
+
	char pathdone[MAXPATHLEN], walkbuf[MAXPATHLEN], *walk;

-
	walk = walkorig = xstrdup(path);
	pathdone[0] = '\0';
-

+
	strlcpy(walkbuf, path, sizeof(walkbuf));
+
	walk = walkbuf;
	while ((next = strsep(&walk, "/")) != NULL) {
		if (*next == '\0')
			continue;
@@ -848,12 +848,10 @@ mkdirat_p(int fd, const char *path)
				continue;
			}
			pkg_errno("Fail to create /%s", pathdone);
-
			free(walkorig);
			return (false);
		}
		strlcat(pathdone, "/", sizeof(pathdone));
	}
-
	free(walkorig);
	return (true);
}