mirror of
https://github.com/apache/nuttx.git
synced 2026-08-01 20:28:58 +00:00
drivers/analog: fix dead free and memory leak in mcp48xx and mcp47x6.
mcp48xx_initialize() and mcp47x6_initialize() share the same two bugs in their allocation error paths: 1. Dead code: when the first kmm_malloc() fails and priv is NULL, the code calls free(priv) which is a no-op on NULL. Remove it. 2. Memory leak: when the second kmm_malloc() fails (dacdev), the function returns NULL without freeing the already-allocated priv. Add kmm_free(priv) before the return. Signed-off-by: hanzj <hanzhijian@zepp.com>
This commit is contained in:
parent
4df7831d48
commit
fa1589a697
2 changed files with 2 additions and 2 deletions
|
|
@ -438,7 +438,6 @@ FAR struct dac_dev_s *mcp47x6_initialize(FAR struct i2c_master_s *i2c,
|
|||
if (priv == NULL)
|
||||
{
|
||||
aerr("ERROR: Failed to allocate mcp47x6_dev_s instance\n");
|
||||
free(priv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -446,6 +445,7 @@ FAR struct dac_dev_s *mcp47x6_initialize(FAR struct i2c_master_s *i2c,
|
|||
if (dacdev == NULL)
|
||||
{
|
||||
aerr("ERROR: Failed to allocate dac_dev_s instance\n");
|
||||
kmm_free(priv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -344,7 +344,6 @@ FAR struct dac_dev_s *mcp48xx_initialize(FAR struct spi_dev_s *spi,
|
|||
if (priv == NULL)
|
||||
{
|
||||
aerr("ERROR: Failed to allocate mcp48xx_dev_s instance\n");
|
||||
free(priv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -352,6 +351,7 @@ FAR struct dac_dev_s *mcp48xx_initialize(FAR struct spi_dev_s *spi,
|
|||
if (dacdev == NULL)
|
||||
{
|
||||
aerr("ERROR: Failed to allocate dac_dev_s instance\n");
|
||||
kmm_free(priv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue