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:
0x7f72546ee850 in malloc (/lib64/libasan.so.4+0xde850)
0x405ff0 in flash_init libflash/test/../libflash.c:830
0x408632 in main libflash/test/test-flash.c:382
0x7f7253540509 in __libc_start_main (/lib64/libc.so.6+0x20509)
@@ -863,8 +863,11 @@ bail:
void flash_exit(struct blocklevel_device *bl)
{
/* XXX Make sure we are idle etc... */
- if (bl)
- free(container_of(bl, struct flash_chip, bl));
+ if (bl) {
+ struct flash_chip *c = container_of(bl, struct flash_chip, bl);
+ free(c->smart_buf);
+ free(c);
+ }
}
void flash_exit_close(struct blocklevel_device *bl, void (*close)(struct spi_flash_ctrl *ctrl))
