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:
hanzj 2026-05-28 16:18:36 +08:00 committed by Xiang Xiao
parent 964be644d6
commit dd5670ed65

View file

@ -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;
}