Skip to content

Commit 1e1bed6

Browse files
committed
btrfs-progs: subvolume create: use stack path buffers
All the variables are for paths or path fragments so we know the upper limit and don't need to allocate the memory dynamically. Signed-off-by: David Sterba <dsterba@suse.com>
1 parent fd856d0 commit 1e1bed6

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

cmds/subvolume.c

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -145,26 +145,15 @@ static int create_one_subvolume(const char *dst, struct btrfs_util_qgroup_inheri
145145
bool create_parents)
146146
{
147147
int ret;
148-
char *dupname = NULL;
149-
char *dupdir = NULL;
148+
char dupname[PATH_MAX];
149+
char dupdir[PATH_MAX];
150150
const char *newname;
151-
char *dstdir;
151+
char *dstdir;
152152
enum btrfs_util_error err;
153153

154-
dupname = strdup(dst);
155-
if (!dupname) {
156-
error_mem("duplicating %s", dst);
157-
ret = -ENOMEM;
158-
goto out;
159-
}
154+
strncpy_null(dupname, dst, PATH_MAX);
160155
newname = path_basename(dupname);
161-
162-
dupdir = strdup(dst);
163-
if (!dupdir) {
164-
error_mem("duplicating %s", dst);
165-
ret = -ENOMEM;
166-
goto out;
167-
}
156+
strncpy_null(dupdir, dst, PATH_MAX);
168157
dstdir = path_dirname(dupdir);
169158

170159
if (create_parents) {
@@ -210,8 +199,6 @@ static int create_one_subvolume(const char *dst, struct btrfs_util_qgroup_inheri
210199
ret = 0;
211200

212201
out:
213-
free(dupname);
214-
free(dupdir);
215202

216203
return ret;
217204
}

0 commit comments

Comments
 (0)