# [PATCH] read-cache: use of memory after it is freed

3 messages from 2018-10-20 to 2018-10-22. Participants: Carlo Marcelo Arenas Belón, Duy Nguyen, Junio C Hamano.
Thread: https://gitlist.dev/t/49623

## Carlo Marcelo Arenas Belón, 2018-10-20 07:33

Subject: [PATCH] read-cache: use of memory after it is freed
Message-ID: <20181020073334.48348-1-carenas@gmail.com>
URL: https://gitlist.dev/e/20181020073334.48348-1-carenas%40gmail.com

```
introduced with c46c406ae1e (trace.h: support nested performance tracing)
on Aug 18, 2018 but not affecting maint

Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
---
 read-cache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/read-cache.c b/read-cache.c
index 1df5c16dbc..78f47d2f50 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -2297,8 +2297,8 @@ int read_index_from(struct index_state *istate, const char *path,
 	freshen_shared_index(base_path, 0);
 	merge_base_index(istate);
 	post_read_index_from(istate);
-	free(base_path);
 	trace_performance_leave("read cache %s", base_path);
+	free(base_path);
 	return ret;
 }
 
-- 
2.19.1


```

## Duy Nguyen, 2018-10-20 15:15

Subject: Re: [PATCH] read-cache: use of memory after it is freed
Message-ID: <CACsJy8B8q84=AqMvAkc5=oSPBbwMQkdQhRe=RYVKGYmnsGxVGA@mail.gmail.com>
URL: https://gitlist.dev/e/CACsJy8B8q84%3DAqMvAkc5%3DoSPBbwMQkdQhRe%3DRYVKGYmnsGxVGA%40mail.gmail.com
In-Reply-To: <20181020073334.48348-1-carenas@gmail.com>

```
On Sat, Oct 20, 2018 at 9:33 AM Carlo Marcelo Arenas Belón
<carenas@gmail.com> wrote:
>
> introduced with c46c406ae1e (trace.h: support nested performance tracing)
> on Aug 18, 2018 but not affecting maint
>
> Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
> ---
>  read-cache.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/read-cache.c b/read-cache.c
> index 1df5c16dbc..78f47d2f50 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -2297,8 +2297,8 @@ int read_index_from(struct index_state *istate, const char *path,
>         freshen_shared_index(base_path, 0);
>         merge_base_index(istate);
>         post_read_index_from(istate);
> -       free(base_path);
>         trace_performance_leave("read cache %s", base_path);
> +       free(base_path);

Oops. Ack.

>         return ret;
>  }
>
> --
> 2.19.1
>


-- 
Duy

```

## Junio C Hamano, 2018-10-22 03:39

Subject: Re: [PATCH] read-cache: use of memory after it is freed
Message-ID: <xmqqva5uwsyd.fsf@gitster-ct.c.googlers.com>
URL: https://gitlist.dev/e/xmqqva5uwsyd.fsf%40gitster-ct.c.googlers.com
In-Reply-To: <CACsJy8B8q84=AqMvAkc5=oSPBbwMQkdQhRe=RYVKGYmnsGxVGA@mail.gmail.com>

```
Duy Nguyen <pclouds@gmail.com> writes:

>>         freshen_shared_index(base_path, 0);
>>         merge_base_index(istate);
>>         post_read_index_from(istate);
>> -       free(base_path);
>>         trace_performance_leave("read cache %s", base_path);
>> +       free(base_path);
>
> Oops. Ack.

Thanks, both.

>> introduced with c46c406ae1e (trace.h: support nested performance tracing)
>> on Aug 18, 2018 but not affecting maint

Yup.  The series nd/unpack-trees-with-cache-tree however was
designed to be merge-able down to 'maint', so it is a good idea to
fix this at the tip of the topic.  So I'll queue it on top of
5f4436a7 ("Document update for nd/unpack-trees-with-cache-tree",
2018-08-25).

```
