mirror of
https://github.com/apache/nuttx.git
synced 2026-08-01 20:28:58 +00:00
drivers/analog: Fix memory leak and dead code in mcp3008_initialize.
Fix two bugs in mcp3008_initialize(): 1. Remove dead free(priv) when priv is NULL (line 382): The first allocation checks if priv == NULL, then calls free(priv) which is a no-op since priv is NULL. Remove the dead call. 2. Add missing kmm_free(priv) when adcdev allocation fails (line 396): If the second kmm_malloc() for adcdev fails, the function returns NULL without freeing the already-allocated priv, causing a memory leak. Add kmm_free(priv) before the return. Signed-off-by: hanzj <hanzjian@zepp.com>
This commit is contained in:
parent
964be644d6
commit
dd5670ed65
1 changed files with 1 additions and 1 deletions
|
|
@ -379,7 +379,6 @@ FAR struct adc_dev_s *mcp3008_initialize(FAR struct spi_dev_s *spi)
|
|||
if (priv == NULL)
|
||||
{
|
||||
aerr("ERROR: Failed to allocate mcp3008_dev_s instance\n");
|
||||
free(priv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -393,6 +392,7 @@ FAR struct adc_dev_s *mcp3008_initialize(FAR struct spi_dev_s *spi)
|
|||
if (adcdev == NULL)
|
||||
{
|
||||
aerr("ERROR: Failed to allocate adc_dev_s instance\n");
|
||||
kmm_free(priv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue