Message ID | 1620775324-23984-6-git-send-email-bmarzins@redhat.com (mailing list archive) |
---|---|
State | Not Applicable, archived |
Delegated to: | christophe varoqui |
Headers | show |
Series | Memory issues found by coverity | expand |
On Tue, 2021-05-11 at 18:22 -0500, Benjamin Marzinski wrote: > If a new block was allocated, but couldn't be filled, getblock will > discard it. When it does so, it needs to free the block to avoid > leaking > memory. Found by coverity. > > Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com> Reviewed-by: Martin Wilck <mwilck@suse.com> -- dm-devel mailing list dm-devel@redhat.com https://listman.redhat.com/mailman/listinfo/dm-devel
diff --git a/kpartx/kpartx.c b/kpartx/kpartx.c index 8ff116b8..7bc64543 100644 --- a/kpartx/kpartx.c +++ b/kpartx/kpartx.c @@ -766,6 +766,8 @@ getblock (int fd, unsigned int blknr) { if (read(fd, bp->block, secsz) != secsz) { fprintf(stderr, "read error, sector %d\n", secnr); blockhead = bp->next; + free(bp->block); + free(bp); return NULL; }
If a new block was allocated, but couldn't be filled, getblock will discard it. When it does so, it needs to free the block to avoid leaking memory. Found by coverity. Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com> --- kpartx/kpartx.c | 2 ++ 1 file changed, 2 insertions(+)