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:
Simon Glass
2025-12-09 08:30:21 -07:00
parent 82be61976f
commit 0987da845d

View File

@@ -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)