Skip to content

Commit 2266bf2

Browse files
author
Junio C Hamano
committed
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>
1 parent 72fe6a5 commit 2266bf2

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

refs.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,7 @@ int for_each_reflog_ent(const char *ref, each_reflog_ent_fn fn, void *cb_data)
11101110
const char *logfile;
11111111
FILE *logfp;
11121112
char buf[1024];
1113+
int ret = 0;
11131114

11141115
logfile = git_path("logs/%s", ref);
11151116
logfp = fopen(logfile, "r");
@@ -1119,7 +1120,7 @@ int for_each_reflog_ent(const char *ref, each_reflog_ent_fn fn, void *cb_data)
11191120
unsigned char osha1[20], nsha1[20];
11201121
char *email_end, *message;
11211122
unsigned long timestamp;
1122-
int len, ret, tz;
1123+
int len, tz;
11231124

11241125
/* old SP new SP name <email> SP time TAB msg LF */
11251126
len = strlen(buf);
@@ -1140,9 +1141,9 @@ int for_each_reflog_ent(const char *ref, each_reflog_ent_fn fn, void *cb_data)
11401141
message += 7;
11411142
ret = fn(osha1, nsha1, buf+82, timestamp, tz, message, cb_data);
11421143
if (ret)
1143-
return ret;
1144+
break;
11441145
}
11451146
fclose(logfp);
1146-
return 0;
1147+
return ret;
11471148
}
11481149

0 commit comments

Comments
 (0)