Replace a few more str(n)dupa by str(n)dup + free

strdup and strndup still don't exist on bionic, so we need to do the
alloc() call ourselves or free the memory by hand.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com>
This commit is contained in:
Stéphane Graber 2013-08-16 14:57:44 +02:00
parent 1d374b9725
commit d74325c436
No known key found for this signature in database
GPG Key ID: C638974D64792D67
2 changed files with 7 additions and 3 deletions

View File

@ -1602,7 +1602,8 @@ static int overlayfs_mount(struct bdev *bdev)
// separately mount it first
// mount -t overlayfs -oupperdir=${upper},lowerdir=${lower} lower dest
dup = strdupa(bdev->src);
dup = alloca(strlen(bdev->src)+1);
strcpy(dup, bdev->src);
if (!(lower = index(dup, ':')))
return -22;
if (!(upper = index(++lower, ':')))
@ -1770,7 +1771,8 @@ static int overlayfs_create(struct bdev *bdev, const char *dest, const char *n,
return -1;
}
delta = strdupa(dest);
delta = alloca(strlen(dest)+1);
strcpy(delta, dest);
strcpy(delta+len-6, "delta0");
if (mkdir_p(delta, 0755) < 0) {

View File

@ -184,13 +184,15 @@ extern int mkdir_p(const char *dir, mode_t mode)
do {
dir = tmp + strspn(tmp, "/");
tmp = dir + strcspn(dir, "/");
makeme = strndupa(orig, dir - orig);
makeme = strndup(orig, dir - orig);
if (*makeme) {
if (mkdir(makeme, mode) && errno != EEXIST) {
SYSERROR("failed to create directory '%s'\n", makeme);
free(makeme);
return -1;
}
}
free(makeme);
} while(tmp != dir);
return 0;