Skip to content

Commit 8a31893

Browse files
committed
libflash: fix memory leak on flash_exit()
LeakSanitizer caught this with libflash/test/test-flash.c: Direct leak of 4096 byte(s) in 1 object(s) allocated from: #0 0x7f72546ee850 in malloc (/lib64/libasan.so.4+0xde850) #1 0x405ff0 in flash_init libflash/test/../libflash.c:830 #2 0x408632 in main libflash/test/test-flash.c:382 open-power#3 0x7f7253540509 in __libc_start_main (/lib64/libc.so.6+0x20509) Signed-off-by: Stewart Smith <[email protected]>
1 parent 8654891 commit 8a31893

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

libflash/libflash.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -863,8 +863,11 @@ int flash_init(struct spi_flash_ctrl *ctrl, struct blocklevel_device **bl,
863863
void flash_exit(struct blocklevel_device *bl)
864864
{
865865
/* XXX Make sure we are idle etc... */
866-
if (bl)
867-
free(container_of(bl, struct flash_chip, bl));
866+
if (bl) {
867+
struct flash_chip *c = container_of(bl, struct flash_chip, bl);
868+
free(c->smart_buf);
869+
free(c);
870+
}
868871
}
869872

870873
void flash_exit_close(struct blocklevel_device *bl, void (*close)(struct spi_flash_ctrl *ctrl))

0 commit comments

Comments
 (0)