xbps_symlink_target: fix a memleak.
This commit is contained in:
parent
a05e039cce
commit
6d65e76f91
28
lib/util.c
28
lib/util.c
@ -457,7 +457,7 @@ char *
|
|||||||
xbps_symlink_target(struct xbps_handle *xhp, const char *path, const char *tgt)
|
xbps_symlink_target(struct xbps_handle *xhp, const char *path, const char *tgt)
|
||||||
{
|
{
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
char *p, *p1, *dname, *res = NULL, *lnk = NULL;
|
char *res = NULL, *lnk = NULL;
|
||||||
ssize_t r;
|
ssize_t r;
|
||||||
|
|
||||||
if (lstat(path, &sb) == -1)
|
if (lstat(path, &sb) == -1)
|
||||||
@ -482,33 +482,33 @@ xbps_symlink_target(struct xbps_handle *xhp, const char *path, const char *tgt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (strstr(lnk, "./") || lnk[0] != '/') {
|
if (strstr(lnk, "./") || lnk[0] != '/') {
|
||||||
|
char *p, *p1, *dname, labs[PATH_MAX];
|
||||||
/* relative */
|
/* relative */
|
||||||
p = strdup(path);
|
p = strdup(path);
|
||||||
assert(p);
|
assert(p);
|
||||||
dname = dirname(p);
|
dname = dirname(p);
|
||||||
assert(dname);
|
assert(dname);
|
||||||
p = xbps_xasprintf("%s/%s", dname, lnk);
|
snprintf(labs, sizeof(labs), "%s/%s", dname, lnk);
|
||||||
assert(p);
|
|
||||||
p1 = xbps_sanitize_path(p);
|
|
||||||
assert(p1);
|
|
||||||
free(p);
|
free(p);
|
||||||
if ((strstr(p1, "./")) && (p = realpath(p1, NULL))) {
|
p = xbps_sanitize_path(labs);
|
||||||
|
assert(p);
|
||||||
|
if ((strstr(p, "./")) && (p1 = realpath(p, NULL))) {
|
||||||
if (strcmp(xhp->rootdir, "/") == 0)
|
if (strcmp(xhp->rootdir, "/") == 0)
|
||||||
res = strdup(p);
|
res = p1;
|
||||||
else
|
else {
|
||||||
res = strdup(p + strlen(xhp->rootdir));
|
res = strdup(p1 + strlen(xhp->rootdir));
|
||||||
|
free(p1);
|
||||||
free(p);
|
}
|
||||||
}
|
}
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
if (strcmp(xhp->rootdir, "/") == 0)
|
if (strcmp(xhp->rootdir, "/") == 0)
|
||||||
res = strdup(p1);
|
res = p;
|
||||||
else
|
else
|
||||||
res = strdup(p1 + strlen(xhp->rootdir));
|
res = strdup(p + strlen(xhp->rootdir));
|
||||||
}
|
}
|
||||||
assert(res);
|
assert(res);
|
||||||
free(lnk);
|
free(lnk);
|
||||||
free(p1);
|
free(p);
|
||||||
} else {
|
} else {
|
||||||
/* absolute */
|
/* absolute */
|
||||||
res = lnk;
|
res = lnk;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user