Author: Lars Hjemli <hjemli@gmail.com>
shared.c: avoid memory leak during diff Signed-off-by: Lars Hjemli <hjemli@gmail.com>
shared.c | 8 ++++++++
diff --git a/shared.c b/shared.c index 9362d2114e44a5f3c5cd9cd81853d854ed745c79..6adf2b6361c42cd2f8bd6356a97fe08821bcb1a4 100644 --- a/shared.c +++ b/shared.c @@ -278,6 +278,10 @@ 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 @@ emit_params.flags = XDL_EMIT_FUNCNAMES; 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; }