Do not use invalid reference to the heap

One should never return from a function the address of data allocated on
the heap in that function, because with the end of that function, the
address range is freed for other purposes.

Work around the thinko by making the buffer static. This is far from
ideal, but a work-around.

This fixes a regression introduced in 859c301(refs: split log_ref_write
logic into log_ref_setup).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin
2010-06-11 23:39:47 +02:00
parent f48154a75a
commit 5b82c4d7b5

2
refs.c
View File

@@ -1265,7 +1265,7 @@ static int copy_msg(char *buf, const char *msg)
int log_ref_setup(const char *ref_name, char **log_file)
{
int logfd, oflags = O_APPEND | O_WRONLY;
char logfile[PATH_MAX];
static char logfile[PATH_MAX];
git_snpath(logfile, sizeof(logfile), "logs/%s", ref_name);
*log_file = logfile;