Whamcloud - gitweb
misc/fsck: fix potential memory leak on error path
authorTheodore Ts'o <tytso@mit.edu>
Sun, 11 Mar 2018 00:44:37 +0000 (19:44 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 11 Mar 2018 02:23:16 +0000 (21:23 -0500)
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
misc/fsck.c

index a2e0dfb..cd23537 100644 (file)
@@ -441,13 +441,14 @@ static int execute(const char *type, const char *device, const char *mntpt,
        struct fsck_instance *inst, *p;
        pid_t   pid;
 
+       if (snprintf(prog, sizeof(prog), "fsck.%s", type) >= sizeof(prog))
+               return EINVAL;
+
        inst = malloc(sizeof(struct fsck_instance));
        if (!inst)
                return ENOMEM;
        memset(inst, 0, sizeof(struct fsck_instance));
 
-       if (snprintf(prog, sizeof(prog), "fsck.%s", type) >= sizeof(prog))
-               return EINVAL;
        argv[0] = string_copy(prog);
        argc = 1;