From ff8d8d42701126cf776de2a011e84dc75787bbb9 Mon Sep 17 00:00:00 2001 From: Jinjuan Qiu Date: Thu, 9 Sep 2021 16:27:06 +0800 Subject: [PATCH] dsp: bugfix for memory leak in error handling path Add extra goto label in order to free memory in case program failed to acquire memory through callback_node. With the original code, there might be a situation where the memory acquired by client_info_node will not be freed, thus causing possible memory leak. Change-Id: If5c8a4bdfbed4ada57a7563e9e212dc9aa7caab0 Signed-off-by: Jinjuan Qiu --- dsp/audio_calibration.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) mode change 100755 => 100644 dsp/audio_calibration.c diff --git a/dsp/audio_calibration.c b/dsp/audio_calibration.c old mode 100755 new mode 100644 index c2fb702fbde3..c4ab399a38af --- a/dsp/audio_calibration.c +++ b/dsp/audio_calibration.c @@ -148,7 +148,7 @@ int audio_cal_register(int num_cal_types, GFP_KERNEL); if (callback_node == NULL) { ret = -ENOMEM; - goto err; + goto err_callback_node; } memcpy(callback_node, ®_data[i].callbacks, @@ -160,10 +160,13 @@ int audio_cal_register(int num_cal_types, &audio_cal.client_info[reg_data[i].cal_type]); mutex_unlock(&audio_cal.cal_mutex[reg_data[i].cal_type]); } -done: - return ret; + goto done; + +err_callback_node: + kfree(client_info_node); err: audio_cal_deregister(num_cal_types, reg_data); +done: return ret; }