Skip to content

Commit

Permalink
Fix OOM bug when using diffwr option
Browse files Browse the repository at this point in the history
Before this patch, free() was called only when blocks were not the same,
causing memory leaks when they were, what could eventually cause an OOM
due to the accumulated effect of those leaks on large files.

This patch frees allocated memory for both paths, thus fixing the bug.
Thanks @szolnokit for the report.

Closes #16.
  • Loading branch information
davidpolverari committed Apr 15, 2023
1 parent 0fac473 commit 2cddf08
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/full-write.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ full_write (int desc, const char *ptr, size_t len, int diffwr)
if ((pos >= 0) && (rptr = malloc(len))) {
int rlen = safe_read(desc, rptr, len);
if ((rlen <= 0) || (rlen != len) || (memcmp(rptr, ptr, len))) {
free(rptr);
lseek(desc, pos, SEEK_SET);
} else {
written = len;
}
free(rptr);
}
}
if (written <= 0) {
Expand Down

0 comments on commit 2cddf08

Please sign in to comment.