VirtualBox

Changeset 77700 in vbox


Ignore:
Timestamp:
Mar 14, 2019 12:41:50 AM (6 years ago)
Author:
vboxsync
Message:

Runtime/json: Plug small memory leak when parsing a JSON file fails

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/misc/json.cpp

    r76553 r77700  
    934934
    935935/**
     936 * Cleans up any resources still in control of the given token.
     937 *
     938 * @returns nothing.
     939 * @param   pToken              The toke nto clean up.
     940 */
     941static void rtJsonTokenizerTokenCleanup(PRTJSONTOKEN pToken)
     942{
     943    if (   pToken->enmClass == RTJSONTOKENCLASS_STRING
     944        && pToken->Class.String.pszStr)
     945        RTStrFree(pToken->Class.String.pszStr);
     946}
     947
     948/**
    936949 * Destroys a given tokenizer state.
    937950 *
     
    941954static void rtJsonTokenizerDestroy(PRTJSONTOKENIZER pTokenizer)
    942955{
    943     RT_NOREF_PV(pTokenizer);
     956    rtJsonTokenizerTokenCleanup(pTokenizer->pTokenCurr);
     957    rtJsonTokenizerTokenCleanup(pTokenizer->pTokenNext);
    944958}
    945959
     
    11561170    {
    11571171        char *pszName = pToken->Class.String.pszStr; /* We can consume this string as it was allocated. */
     1172        pToken->Class.String.pszStr = NULL;
    11581173
    11591174        rtJsonTokenizerConsume(pTokenizer);
     
    11771192                        if (papszNamesNew)
    11781193                            RTMemFree(papszNamesNew);
     1194                        RTStrFree(pszName);
    11791195                        rc = VERR_NO_MEMORY;
    11801196                        break;
     
    12001216                                       pTokenizer->Pos.iLine, pTokenizer->Pos.iChStart);
    12011217            }
     1218            else
     1219                RTStrFree(pszName);
    12021220        }
    12031221        else
     1222        {
     1223            RTStrFree(pszName);
    12041224            rc = RTErrInfoSetF(pTokenizer->pErrInfo, VERR_JSON_MALFORMED, "expected name separator (line %zu col %zu)",
    12051225                               pTokenizer->Pos.iLine, pTokenizer->Pos.iChStart);
     1226        }
    12061227    }
    12071228
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette