for_each_reflog_ent: do not leak FILE *
The callback function can signal an early return by returning non-zero, but the function leaked the FILE * opened on the reflog when doing so. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Jan 18, 2007 at 23:25 UTC
2266bf27b354a08522406eff916898b6300ddfa0
1 file changed
+4
-3
refs.c
+4
-3
@@ -1110,6 +1110,7 @@ int for_each_reflog_ent(const char *ref, each_reflog_ent_fn fn, void *cb_data)
1110
const char *logfile;
1111
FILE *logfp;
1112
char buf[1024];
1113
+ int ret = 0;
1114
1115
logfile = git_path("logs/%s", ref);
1116
logfp = fopen(logfile, "r");
@@ -1119,7 +1120,7 @@ int for_each_reflog_ent(const char *ref, each_reflog_ent_fn fn, void *cb_data)
1120
unsigned char osha1[20], nsha1[20];
1121
char *email_end, *message;
1122
unsigned long timestamp;
1122
- int len, ret, tz;
1123
+ int len, tz;
1124
1125
/* old SP new SP name <email> SP time TAB msg LF */
1126
len = strlen(buf);
@@ -1140,9 +1141,9 @@ int for_each_reflog_ent(const char *ref, each_reflog_ent_fn fn, void *cb_data)
1141
message += 7;
1142
ret = fn(osha1, nsha1, buf+82, timestamp, tz, message, cb_data);
1143
if (ret)
1143
- return ret;
1144
+ break;
1145
}
1146
fclose(logfp);
1146
- return 0;
1147
+ return ret;
1148
}
1149