All of lore.kernel.org
 help / color / mirror / Atom feed
* lib/argv_split.c : should argv be kfree'ed ?
@ 2014-06-28 21:52 Toralf Förster
  2014-06-28 22:04 ` Mateusz Guzik
  0 siblings, 1 reply; 4+ messages in thread
From: Toralf Förster @ 2014-06-28 21:52 UTC (permalink / raw)
  To: Linux Kernel

/me wonders if this patch is needed here :


diff --git a/lib/argv_split.c b/lib/argv_split.c
index e927ed0..7de4cb4 100644
--- a/lib/argv_split.c
+++ b/lib/argv_split.c
@@ -85,6 +85,7 @@ char **argv_split(gfp_t gfp, const char *str, int *argcp)
                        *argv++ = argv_str;
                }
        }
+       kfree (argv);
        *argv = NULL;

        if (argcp)

-- 
Toralf


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: lib/argv_split.c : should argv be kfree'ed ?
  2014-06-28 21:52 lib/argv_split.c : should argv be kfree'ed ? Toralf Förster
@ 2014-06-28 22:04 ` Mateusz Guzik
  2014-06-29 14:40   ` Toralf Förster
  0 siblings, 1 reply; 4+ messages in thread
From: Mateusz Guzik @ 2014-06-28 22:04 UTC (permalink / raw)
  To: Toralf Förster; +Cc: Linux Kernel

On Sat, Jun 28, 2014 at 11:52:37PM +0200, Toralf Förster wrote:
> /me wonders if this patch is needed here :
> 
> 
> diff --git a/lib/argv_split.c b/lib/argv_split.c
> index e927ed0..7de4cb4 100644
> --- a/lib/argv_split.c
> +++ b/lib/argv_split.c
> @@ -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.

-- 
Mateusz Guzik

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: lib/argv_split.c : should argv be kfree'ed ?
  2014-06-28 22:04 ` Mateusz Guzik
@ 2014-06-29 14:40   ` Toralf Förster
  2014-06-29 15:37     ` Mateusz Guzik
  0 siblings, 1 reply; 4+ messages in thread
From: Toralf Förster @ 2014-06-29 14:40 UTC (permalink / raw)
  To: Mateusz Guzik; +Cc: Linux Kernel

On 06/29/2014 12:04 AM, Mateusz Guzik wrote:
> On Sat, Jun 28, 2014 at 11:52:37PM +0200, Toralf Förster wrote:
>> /me wonders if this patch is needed here :
>>
>>
>> diff --git a/lib/argv_split.c b/lib/argv_split.c
>> index e927ed0..7de4cb4 100644
>> --- a/lib/argv_split.c
>> +++ b/lib/argv_split.c
>> @@ -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.
> 
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;

-- 
Toralf


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: lib/argv_split.c : should argv be kfree'ed ?
  2014-06-29 14:40   ` Toralf Förster
@ 2014-06-29 15:37     ` Mateusz Guzik
  0 siblings, 0 replies; 4+ messages in thread
From: Mateusz Guzik @ 2014-06-29 15:37 UTC (permalink / raw)
  To: Toralf Förster; +Cc: Linux Kernel

On Sun, Jun 29, 2014 at 04:40:17PM +0200, Toralf Förster wrote:
> On 06/29/2014 12:04 AM, Mateusz Guzik wrote:
> > On Sat, Jun 28, 2014 at 11:52:37PM +0200, Toralf Förster wrote:
> >> /me wonders if this patch is needed here :
> >>
> >>
> >> diff --git a/lib/argv_split.c b/lib/argv_split.c
> >> index e927ed0..7de4cb4 100644
> >> --- a/lib/argv_split.c
> >> +++ b/lib/argv_split.c
> >> @@ -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.
> > 
> 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;
> 


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.

-- 
Mateusz Guzik

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-06-29 15:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-28 21:52 lib/argv_split.c : should argv be kfree'ed ? Toralf Förster
2014-06-28 22:04 ` Mateusz Guzik
2014-06-29 14:40   ` Toralf Förster
2014-06-29 15:37     ` Mateusz Guzik

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.