From 80a22163606b1b3319743fb58387c67aafcbc2da Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Sun, 5 Jan 2020 20:06:15 -0800 Subject: [PATCH] effects: fix a theoretical memory leak `realloc` doesn't deallocate `param` if it fails. Since the loop ends in a `free`, we just need to avoid overwriting `param` until after the check. Caught by the static analyzer: frameworks/av/services/audioflinger/Effects.cpp:1868:9: warning: Potential leak of memory pointed to by 'param' [clang-analyzer-unix.Malloc] Bug: None Test: TreeHugger Change-Id: I58fe4319927b3ea99989e1fb1dc2dabe89c72ef8 --- services/audioflinger/Effects.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/audioflinger/Effects.cpp b/services/audioflinger/Effects.cpp index ee7a6d614b..641f3ecb92 100644 --- a/services/audioflinger/Effects.cpp +++ b/services/audioflinger/Effects.cpp @@ -1856,12 +1856,13 @@ status_t AudioFlinger::EffectHandle::command(uint32_t cmdCode, } // copy to local memory in case of client corruption b/32220769 - param = (effect_param_t *)realloc(param, size); - if (param == NULL) { + auto *newParam = (effect_param_t *)realloc(param, size); + if (newParam == NULL) { ALOGW("command(): out of memory"); status = NO_MEMORY; break; } + param = newParam; memcpy(param, p, size); int reply = 0;