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>
Junio C Hamano committed
Jan 19, 2007 at 00:39 UTC
cb48cb585f3bed37467565ed35889726568a442d
1 file changed
+5
-3
refs.c
+5
-3
@@ -1025,6 +1025,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
1025
struct stat st;
1026
unsigned long date;
1027
unsigned char logged_sha1[20];
1028
+ void *log_mapped;
1029
1030
logfile = git_path("logs/%s", ref);
1031
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 *
1034
fstat(logfd, &st);
1035
if (!st.st_size)
1036
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;
1039
close(logfd);
1040
1041
lastrec = NULL;
@@ -1078,7 +1080,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
1080
logfile, show_rfc2822_date(date, tz));
1081
}
1082
}
1081
- munmap((void*)logdata, st.st_size);
1083
+ munmap(log_mapped, st.st_size);
1084
return 0;
1085
}
1086
lastrec = rec;
@@ -1095,7 +1097,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
1097
tz = strtoul(tz_c, NULL, 10);
1098
if (get_sha1_hex(logdata, sha1))
1099
die("Log %s is corrupt.", logfile);
1098
- munmap((void*)logdata, st.st_size);
1100
+ munmap(log_mapped, st.st_size);
1101
if (at_time)
1102
fprintf(stderr, "warning: Log %s only goes back to %s.\n",
1103
logfile, show_rfc2822_date(date, tz));