From bb977c73e4b75c7729b0be9a2bd201ffd48b4a14 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Mon, 21 Dec 2015 16:55:53 +0100 Subject: [PATCH] xbps_symlink_target: fix a meamleak reported by clang-analyzer. --- lib/util.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/util.c b/lib/util.c index 2615ce7c..1477a6a2 100644 --- a/lib/util.c +++ b/lib/util.c @@ -502,14 +502,13 @@ xbps_symlink_target(struct xbps_handle *xhp, const char *path, const char *tgt) } if (res == NULL) { if (strcmp(xhp->rootdir, "/") == 0) - res = p; - else { + res = strdup(p); + else res = strdup(p + strlen(xhp->rootdir)); - free(p); - } } assert(res); free(lnk); + free(p); } else { /* absolute */ res = lnk;