From 9667587366c8fca4d0a91aaebc771b8bbd9933e8 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Mon, 30 Apr 2018 13:07:53 +0200 Subject: [PATCH] daemon: simplify string allocation When creating an helper string for do_aug_match(), use a simpler asprintf() with manual free(), since the code block is small enough. This slightly helps static code analyzers. --- daemon/augeas.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/daemon/augeas.c b/daemon/augeas.c index bd54c4849..453251337 100644 --- a/daemon/augeas.c +++ b/daemon/augeas.c @@ -420,17 +420,15 @@ do_aug_ls (const char *path) if (STREQ (path, "/")) matches = do_aug_match ("/*"); else { - CLEANUP_FREE char *buf = NULL; + char *buf = NULL; - len += 3; /* / * + terminating \0 */ - buf = malloc (len); - if (buf == NULL) { - reply_with_perror ("malloc"); + if (asprintf (&buf, "%s/*", path) == -1) { + reply_with_perror ("asprintf"); return NULL; } - snprintf (buf, len, "%s/*", path); matches = do_aug_match (buf); + free (buf); } if (matches == NULL)