for_each_reflog_ent: do not leak FILE *
[gitweb.git] / refs.c
diff --git a/refs.c b/refs.c
index 689ac50bae64a1068f2d9b1d720817748fc2289d..87efa38c7e11fa05a320fb140dfcf5cb4e55da3c 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -837,7 +837,12 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)
 
  retry:
        if (log && rename(git_path("tmp-renamed-log"), git_path("logs/%s", newref))) {
-               if (errno==EISDIR) {
+               if (errno==EISDIR || errno==ENOTDIR) {
+                       /*
+                        * rename(a, b) when b is an existing
+                        * directory ought to result in ISDIR, but
+                        * Solaris 5.8 gives ENOTDIR.  Sheesh.
+                        */
                        if (remove_empty_directories(git_path("logs/%s", newref))) {
                                error("Directory not empty: logs/%s", newref);
                                goto rollback;
@@ -1105,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];
+       int ret = 0;
 
        logfile = git_path("logs/%s", ref);
        logfp = fopen(logfile, "r");
@@ -1114,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;
-               int len, ret, tz;
+               int len, tz;
 
                /* old SP new SP name <email> SP time TAB msg LF */
                len = strlen(buf);
@@ -1135,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)
-                       return ret;
+                       break;
        }
        fclose(logfp);
-       return 0;
+       return ret;
 }