Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 03077683 authored by Chih-Hung Hsieh's avatar Chih-Hung Hsieh
Browse files

Fix potential memory leak.

* Do not reset caller's *param to NULL when realloc fails.
  The caller will free *param.

Test: build with WITH_TIDY=1
Change-Id: Iadd800b77fea4ea423d440e6e97e4dfc00c09fcd
parent 4eeaffe5
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -460,12 +460,13 @@ size_t AudioPolicyEffects::readParamValue(cnode *node,
        len = strnlen(node->value, EFFECT_STRING_LEN_MAX);
        if (*curSize + len + 1 > *totSize) {
            *totSize = *curSize + len + 1;
            *param = (char *)realloc(*param, *totSize);
            if (*param == NULL) {
            char *newParam = (char *)realloc(*param, *totSize);
            if (newParam == NULL) {
                len = 0;
                ALOGE("%s realloc error for string len %zu", __func__, *totSize);
                goto exit;
            }
            *param = newParam;
        }
        strncpy(*param + *curSize, node->value, len);
        *curSize += len;