]> granicus.if.org Git - cgit/commitdiff
shared.c: avoid memory leak during diff
authorLars Hjemli <hjemli@gmail.com>
Wed, 7 Apr 2010 22:48:36 +0000 (00:48 +0200)
committerLars Hjemli <hjemli@gmail.com>
Wed, 7 Apr 2010 22:48:36 +0000 (00:48 +0200)
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
shared.c

index 9362d2114e44a5f3c5cd9cd81853d854ed745c79..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.size)
+                       free(file1.ptr);
+               if (file2.size)
+                       free(file2.ptr);
                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);
+       if (file1.size)
+               free(file1.ptr);
+       if (file2.size)
+               free(file2.ptr);
        return 0;
 }