mmc: sandbox: Fix memory leak on probe failure
If mmc_init() fails, the buffer allocated by calloc() or mapped by os_map_file() is not freed. Free or unmap the buffer before returning the error. Signed-off-by: Simon Glass <simon.glass@canonical.com>
This commit is contained in:
@@ -190,7 +190,16 @@ static int sandbox_mmc_probe(struct udevice *dev)
|
||||
}
|
||||
}
|
||||
|
||||
return mmc_init(&plat->mmc);
|
||||
ret = mmc_init(&plat->mmc);
|
||||
if (ret) {
|
||||
if (plat->fname)
|
||||
os_unmap(priv->buf, priv->size);
|
||||
else
|
||||
free(priv->buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sandbox_mmc_remove(struct udevice *dev)
|
||||
|
||||
Reference in New Issue
Block a user