Merge branch 'master' into next

* master:
  refs.c::read_ref_at(): fix bogus munmap() call.
  for_each_reflog_ent: do not leak FILE *
This commit is contained in:
Junio C Hamano
2007-01-19 01:29:22 -08:00

15
refs.c
View File

@@ -1025,6 +1025,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
struct stat st;
unsigned long date;
unsigned char logged_sha1[20];
void *log_mapped;
logfile = git_path("logs/%s", ref);
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 *
fstat(logfd, &st);
if (!st.st_size)
die("Log %s is empty.", logfile);
logdata = xmmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, logfd, 0);
log_mapped = xmmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, logfd, 0);
logdata = log_mapped;
close(logfd);
lastrec = NULL;
@@ -1078,7 +1080,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
logfile, show_rfc2822_date(date, tz));
}
}
munmap((void*)logdata, st.st_size);
munmap(log_mapped, st.st_size);
return 0;
}
lastrec = rec;
@@ -1095,7 +1097,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
tz = strtoul(tz_c, NULL, 10);
if (get_sha1_hex(logdata, sha1))
die("Log %s is corrupt.", logfile);
munmap((void*)logdata, st.st_size);
munmap(log_mapped, st.st_size);
if (at_time)
fprintf(stderr, "warning: Log %s only goes back to %s.\n",
logfile, show_rfc2822_date(date, tz));
@@ -1110,6 +1112,7 @@ int for_each_reflog_ent(const char *ref, each_reflog_ent_fn fn, void *cb_data)
const char *logfile;
FILE *logfp;
char buf[1024];
int ret = 0;
logfile = git_path("logs/%s", ref);
logfp = fopen(logfile, "r");
@@ -1119,7 +1122,7 @@ int for_each_reflog_ent(const char *ref, each_reflog_ent_fn fn, void *cb_data)
unsigned char osha1[20], nsha1[20];
char *email_end, *message;
unsigned long timestamp;
int len, ret, tz;
int len, tz;
/* old SP new SP name <email> SP time TAB msg LF */
len = strlen(buf);
@@ -1140,9 +1143,9 @@ int for_each_reflog_ent(const char *ref, each_reflog_ent_fn fn, void *cb_data)
message += 7;
ret = fn(osha1, nsha1, buf+82, timestamp, tz, message, cb_data);
if (ret)
return ret;
break;
}
fclose(logfp);
return 0;
return ret;
}