threads / patch / 49799

patchbuiltin/notes: remove unnecessary free

Subject: [PATCH] builtin/notes: remove unnecessary free

## tl;dr

3 messages between Nov 11, 2018 and Nov 13, 2018. Diffs are folded; open one to read it.

replies: 2people: 3as markdown or json

Carlo Marcelo Arenas Belón· Nov 11, 2018, 09:49 UTC · lore

511726e4b1 ("builtin/notes: fix premature failure when trying to add the empty blob", 2014-11-09) removed the check for !len but left a call to free the buffer that will be otherwise NULL

Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
---
 builtin/notes.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
Show changes to builtin/notes.c +1 −3
diff --git a/builtin/notes.c b/builtin/notes.c
index c05cd004ab..68062f7475 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -255,10 +255,8 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
 
 	if (get_oid(arg, &object))
 		die(_("failed to resolve '%s' as a valid ref."), arg);
-	if (!(buf = read_object_file(&object, &type, &len))) {
-		free(buf);
+	if (!(buf = read_object_file(&object, &type, &len)))
 		die(_("failed to read object '%s'."), arg);
-	}
 	if (type != OBJ_BLOB) {
 		free(buf);
 		die(_("cannot read note data from non-blob object '%s'."), arg);
-- 
2.19.1.856.g8858448bb
Johan Herland· Nov 11, 2018, 10:41 UTC · re: Carlo Marcelo Arenas Belón · lore

Re: [PATCH] builtin/notes: remove unnecessary free

On Sun, Nov 11, 2018 at 10:49 AM Carlo Marcelo Arenas Belón <carenas@gmail.com> wrote:

Show 6 quoted lines
>
> 511726e4b1 ("builtin/notes: fix premature failure when trying to add
> the empty blob", 2014-11-09) removed the check for !len but left a
> call to free the buffer that will be otherwise NULL
>
> Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
Signed-off-by: Johan Herland <johan@herland.net>
Show 23 quoted lines
> ---
>  builtin/notes.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/builtin/notes.c b/builtin/notes.c
> index c05cd004ab..68062f7475 100644
> --- a/builtin/notes.c
> +++ b/builtin/notes.c
> @@ -255,10 +255,8 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
>
>         if (get_oid(arg, &object))
>                 die(_("failed to resolve '%s' as a valid ref."), arg);
> -       if (!(buf = read_object_file(&object, &type, &len))) {
> -               free(buf);
> +       if (!(buf = read_object_file(&object, &type, &len)))
>                 die(_("failed to read object '%s'."), arg);
> -       }
>         if (type != OBJ_BLOB) {
>                 free(buf);
>                 die(_("cannot read note data from non-blob object '%s'."), arg);
> --
> 2.19.1.856.g8858448bb
>
-- 
Johan Herland, <johan@herland.net>
www.herland.net
Junio C Hamano· Nov 13, 2018, 01:29 UTC · re: Johan Herland · lore

Re: [PATCH] builtin/notes: remove unnecessary free

Johan Herland <johan@herland.net> writes:
Show 6 quoted lines
> On Sun, Nov 11, 2018 at 10:49 AM Carlo Marcelo Arenas Belón
> <carenas@gmail.com> wrote:
>>
>> 511726e4b1 ("builtin/notes: fix premature failure when trying to add
>> the empty blob", 2014-11-09) removed the check for !len but left a
>> call to free the buffer that will be otherwise NULL
Wow, that's a old one.
>>
>> Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
>
> Signed-off-by: Johan Herland <johan@herland.net>
Thanks, both.  Will apply.

← back to recent threads