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;