for_each_reflog_ent: do not leak FILE *
authorJunio C Hamano <junkio@cox.net>
Fri, 19 Jan 2007 07:25:54 +0000 (23:25 -0800)
committerJunio C Hamano <junkio@cox.net>
Fri, 19 Jan 2007 07:25:54 +0000 (23:25 -0800)
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>
refs.c

diff --git a/refs.c b/refs.c
index 7d85863..87efa38 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -1110,6 +1110,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];
        const char *logfile;
        FILE *logfp;
        char buf[1024];
+       int ret = 0;
 
        logfile = git_path("logs/%s", ref);
        logfp = fopen(logfile, "r");
 
        logfile = git_path("logs/%s", ref);
        logfp = fopen(logfile, "r");
@@ -1119,7 +1120,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;
                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);
 
                /* old SP new SP name <email> SP time TAB msg LF */
                len = strlen(buf);
@@ -1140,9 +1141,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)
                message += 7;
                ret = fn(osha1, nsha1, buf+82, timestamp, tz, message, cb_data);
                if (ret)
-                       return ret;
+                       break;
        }
        fclose(logfp);
        }
        fclose(logfp);
-       return 0;
+       return ret;
 }
 
 }