]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (script) fix possible memory leaks
authorKarel Zak <kzak@redhat.com>
Thu, 13 Aug 2020 11:48:28 +0000 (13:48 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 13 Nov 2020 10:50:53 +0000 (11:50 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/script.c

index 8eb62dcbfe07b879a0253b7967d5f8a424398949..ea16f139267dd6ab1a5cad37fdca4406e4a39805 100644 (file)
@@ -636,6 +636,7 @@ static int write_file_json(struct fdisk_script *dp, FILE *f)
                        fputs("\"node\":", f);
                        fputs_quoted_json(p, f);
                        nvars++;
+                       free(p);
                }
 
                if (fdisk_partition_has_start(pa)) {
@@ -737,6 +738,7 @@ static int write_file_sfdisk(struct fdisk_script *dp, FILE *f)
                if (p) {
                        DBG(SCRIPT, ul_debugobj(dp, "write %s entry", p));
                        fprintf(f, "%s :", p);
+                       free(p);
                } else
                        fprintf(f, "%zu :", pa->partno + 1);
 
@@ -1068,14 +1070,17 @@ static int parse_line_nameval(struct fdisk_script *dp, char *s)
 
                } else if (!strncasecmp(p, "attrs=", 6)) {
                        p += 6;
+                       free(pa->attrs);
                        rc = next_string(&p, &pa->attrs);
 
                } else if (!strncasecmp(p, "uuid=", 5)) {
                        p += 5;
+                       free(pa->uuid);
                        rc = next_string(&p, &pa->uuid);
 
                } else if (!strncasecmp(p, "name=", 5)) {
                        p += 5;
+                       free(pa->name);
                        rc = next_string(&p, &pa->name);
                        if (!rc)
                                unhexmangle_string(pa->name);
@@ -1124,7 +1129,7 @@ static int parse_line_nameval(struct fdisk_script *dp, char *s)
 static int parse_line_valcommas(struct fdisk_script *dp, char *s)
 {
        int rc = 0;
-       char *p = s, *str;
+       char *p = s;
        struct fdisk_partition *pa;
        enum { ITEM_START, ITEM_SIZE, ITEM_TYPE, ITEM_BOOTABLE };
        int item = -1;
@@ -1209,6 +1214,9 @@ static int parse_line_valcommas(struct fdisk_script *dp, char *s)
                        }
                        break;
                case ITEM_TYPE:
+               {
+                       char *str = NULL;
+
                        if (*p == ',' || *p == ';' || alone_sign(sign, p))
                                break;  /* use default type */
 
@@ -1223,6 +1231,7 @@ static int parse_line_valcommas(struct fdisk_script *dp, char *s)
                        if (!pa->type)
                                rc = -EINVAL;
                        break;
+               }
                case ITEM_BOOTABLE:
                        if (*p == ',' || *p == ';')
                                break;