Skip to contentSkip to conversation

lib/argv_split.c : should argv be kfree'ed ?

PATCH Toralf Förster 2 participants 4 messages Jun 28, 2014 – Jun 29, 2014 Library code

lore
Share & tools
lore
#0 lore raw

/me wonders if this patch is needed here :

lib/argv_split.c +1 -0
index e927ed0..7de4cb4 100644
@@ -85,6 +85,7 @@ char **argv_split(gfp_t gfp, const char *str, int *argcp)
                        *argv++ = argv_str;
                }
        }
+       kfree (argv);
        *argv = NULL;
 
        if (argcp)
Signature · 1 line
Toralf
#1 lore raw
Quoted 9 lines · Toralf Förster

/me wonders if this patch is needed here :

lib/argv_split.c +0 -0
index e927ed0..7de4cb4 100644

lib/argv_split.c char **argv_split(gfp_t gfp, const char *str, int *argcp) · line 91

Quoted 7 lines
lib/argv_split.c +1 -0
@@ -85,6 +85,7 @@ char **argv_split(gfp_t gfp, const char *str, int *argcp)
                        *argv++ = argv_str;
                }
        }
+       kfree (argv);
        *argv = NULL;
 
        if (argcp)

No, see argv_free.

Signature · 1 line
Mateusz Guzik
#2 lore raw
Quoted 15 lines · Mateusz Guzik
Quoted 14 lines · Toralf Förster

/me wonders if this patch is needed here :

lib/argv_split.c +1 -0
index e927ed0..7de4cb4 100644
@@ -85,6 +85,7 @@ char **argv_split(gfp_t gfp, const char *str, int *argcp)
                        *argv++ = argv_str;
                }
        }
+       kfree (argv);
        *argv = NULL;
 
Quoted 5 lines

lib/argv_split.c char **argv_split(gfp_t gfp, const char *str, int *argcp) · line 91

Quoted 2 lines
lib/argv_split.c +0 -0
        if (argcp)

No, see argv_free.

Ah, understood, it is in the responsibility of the caller to avoid the memleak. BTW may I ask you about your opinion about this warning of cppcheck in lib/flex_array.c:

        for (part_nr = start_part; part_nr <= end_part; part_nr++) {<--- Memory leak: part
                part = __fa_get_part(fa, part_nr, flags);
                if (!part)
                        return -ENOMEM;
        }
        return 0;
Signature · 1 line
Toralf
#3 lore raw
Quoted 24 lines · Toralf Förster
Quoted 15 lines · Mateusz Guzik
Quoted 14 lines · Toralf Förster

/me wonders if this patch is needed here :

lib/argv_split.c +1 -0
index e927ed0..7de4cb4 100644
@@ -85,6 +85,7 @@ char **argv_split(gfp_t gfp, const char *str, int *argcp)
                        *argv++ = argv_str;
                }
        }
+       kfree (argv);
        *argv = NULL;
 
Quoted 5 lines

lib/argv_split.c char **argv_split(gfp_t gfp, const char *str, int *argcp) · line 91

Quoted 2 lines
lib/argv_split.c +0 -0
        if (argcp)

No, see argv_free.

Ah, understood, it is in the responsibility of the caller to avoid the memleak. BTW may I ask you about your opinion about this warning of cppcheck in lib/flex_array.c:

Quoted 7 lines
        for (part_nr = start_part; part_nr <= end_part; part_nr++) {<--- Memory leak: part
                part = __fa_get_part(fa, part_nr, flags);
                if (!part)
                        return -ENOMEM;
        }
        return 0;

static struct flex_array_part *
__fa_get_part(struct flex_array *fa, int part_nr, gfp_t flags)

{
        struct flex_array_part *part = fa->parts[part_nr];
        if (!part) {
                part = kmalloc(sizeof(struct flex_array_part), flags);
                if (!part)
                        return NULL;
                if (!(flags & __GFP_ZERO))
                        memset(part, FLEX_ARRAY_FREE,
                                sizeof(struct flex_array_part));
                fa->parts[part_nr] = part;

		^^^^^^^^^^^^^^^^^^^^^^^^^^
        }
        return part;
}

Allocated memory is not leaked. It is stored in 'fa' and is perfectly reachable afterwards.

'part' in flex_array_prealloc is only used for error checking.

Signature · 1 line
Mateusz Guzik