]> gitweb.ps.run Git - ps-cgit/blobdiff - shared.c
CGIT 0.8.3.2
[ps-cgit] / shared.c
index d7b2d5a9efe777acc8140ae9401b9c9d17a5fd79..6adf2b6361c42cd2f8bd6356a97fe08821bcb1a4 100644 (file)
--- a/shared.c
+++ b/shared.c
@@ -278,6 +278,10 @@ int cgit_diff_files(const unsigned char *old_sha1,
        if ((file1.ptr && buffer_is_binary(file1.ptr, file1.size)) ||
            (file2.ptr && buffer_is_binary(file2.ptr, file2.size))) {
                *binary = 1;
        if ((file1.ptr && buffer_is_binary(file1.ptr, file1.size)) ||
            (file2.ptr && buffer_is_binary(file2.ptr, file2.size))) {
                *binary = 1;
+               if (file1.size)
+                       free(file1.ptr);
+               if (file2.size)
+                       free(file2.ptr);
                return 0;
        }
 
                return 0;
        }
 
@@ -290,6 +294,10 @@ int cgit_diff_files(const unsigned char *old_sha1,
        emit_cb.outf = filediff_cb;
        emit_cb.priv = fn;
        xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb);
        emit_cb.outf = filediff_cb;
        emit_cb.priv = fn;
        xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb);
+       if (file1.size)
+               free(file1.ptr);
+       if (file2.size)
+               free(file2.ptr);
        return 0;
 }
 
        return 0;
 }
 
@@ -400,18 +408,25 @@ int cgit_close_filter(struct cgit_filter *filter)
  */
 int readfile(const char *path, char **buf, size_t *size)
 {
  */
 int readfile(const char *path, char **buf, size_t *size)
 {
-       int fd;
+       int fd, e;
        struct stat st;
 
        fd = open(path, O_RDONLY);
        if (fd == -1)
                return errno;
        struct stat st;
 
        fd = open(path, O_RDONLY);
        if (fd == -1)
                return errno;
-       if (fstat(fd, &st))
-               return errno;
-       if (!S_ISREG(st.st_mode))
+       if (fstat(fd, &st)) {
+               e = errno;
+               close(fd);
+               return e;
+       }
+       if (!S_ISREG(st.st_mode)) {
+               close(fd);
                return EISDIR;
                return EISDIR;
+       }
        *buf = xmalloc(st.st_size + 1);
        *size = read_in_full(fd, *buf, st.st_size);
        *buf = xmalloc(st.st_size + 1);
        *size = read_in_full(fd, *buf, st.st_size);
+       e = errno;
        (*buf)[*size] = '\0';
        (*buf)[*size] = '\0';
-       return (*size == st.st_size ? 0 : errno);
+       close(fd);
+       return (*size == st.st_size ? 0 : e);
 }
 }