# [PATCH] builtin/notes: remove unnecessary free

3 messages from 2018-11-11 to 2018-11-13. Participants: Carlo Marcelo Arenas Belón, Johan Herland, Junio C Hamano.
Thread: https://gitlist.dev/t/49799

## Carlo Marcelo Arenas Belón, 2018-11-11 09:49

Subject: [PATCH] builtin/notes: remove unnecessary free
Message-ID: <20181111094933.27325-1-carenas@gmail.com>
URL: https://gitlist.dev/e/20181111094933.27325-1-carenas%40gmail.com

```
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(-)

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, 2018-11-11 10:41

Subject: Re: [PATCH] builtin/notes: remove unnecessary free
Message-ID: <CALKQrgdCNxXSOG-KRUeNaw2q=hOGh9+-zM5ATHwmDEmOC7UAcw@mail.gmail.com>
URL: https://gitlist.dev/e/CALKQrgdCNxXSOG-KRUeNaw2q%3DhOGh9%2B-zM5ATHwmDEmOC7UAcw%40mail.gmail.com
In-Reply-To: <20181111094933.27325-1-carenas@gmail.com>

```
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
>
> Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>

Signed-off-by: Johan Herland <johan@herland.net>

> ---
>  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, 2018-11-13 01:29

Subject: Re: [PATCH] builtin/notes: remove unnecessary free
Message-ID: <xmqqh8glzrx8.fsf@gitster-ct.c.googlers.com>
URL: https://gitlist.dev/e/xmqqh8glzrx8.fsf%40gitster-ct.c.googlers.com
In-Reply-To: <CALKQrgdCNxXSOG-KRUeNaw2q=hOGh9+-zM5ATHwmDEmOC7UAcw@mail.gmail.com>

```
Johan Herland <johan@herland.net> writes:

> 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.


```
