Skip to content

Commit cb48cb5

Browse files
author
Junio C Hamano
committed
refs.c::read_ref_at(): fix bogus munmap() call.
The code uses mmap() to read reflog data, but moves the pointer around while reading, and uses that updated pointer in the call to munmap(). Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 2266bf2 commit cb48cb5

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

refs.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
10251025
struct stat st;
10261026
unsigned long date;
10271027
unsigned char logged_sha1[20];
1028+
void *log_mapped;
10281029

10291030
logfile = git_path("logs/%s", ref);
10301031
logfd = open(logfile, O_RDONLY, 0);
@@ -1033,7 +1034,8 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
10331034
fstat(logfd, &st);
10341035
if (!st.st_size)
10351036
die("Log %s is empty.", logfile);
1036-
logdata = xmmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, logfd, 0);
1037+
log_mapped = xmmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, logfd, 0);
1038+
logdata = log_mapped;
10371039
close(logfd);
10381040

10391041
lastrec = NULL;
@@ -1078,7 +1080,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
10781080
logfile, show_rfc2822_date(date, tz));
10791081
}
10801082
}
1081-
munmap((void*)logdata, st.st_size);
1083+
munmap(log_mapped, st.st_size);
10821084
return 0;
10831085
}
10841086
lastrec = rec;
@@ -1095,7 +1097,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
10951097
tz = strtoul(tz_c, NULL, 10);
10961098
if (get_sha1_hex(logdata, sha1))
10971099
die("Log %s is corrupt.", logfile);
1098-
munmap((void*)logdata, st.st_size);
1100+
munmap(log_mapped, st.st_size);
10991101
if (at_time)
11001102
fprintf(stderr, "warning: Log %s only goes back to %s.\n",
11011103
logfile, show_rfc2822_date(date, tz));

0 commit comments

Comments
 (0)