Uploaded image for project: 'HPCC'
  1. HPCC
  2. HPCC-10184

static uncompress in jptree.cpp: potential memory leak

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.2.0
    • Component/s: JLib
    • Labels:
      None
    • Environment:
      Linux OS (Ubuntu)

      Description

      In the static function uncompress(const void *src, size32_t &sz) in system/jlib/jptree.cpp (line 805):

      • The uncompressedValue variable is declared both outside and inside the try block. The variable declared and initialized inside the try block will never be free'd in case of an exception. This leads to a potential memory leak.
      • One solution is to declare the uncompressedValue variable only outside the try block and initialize it inside the try block. See fixed code below.
        static void *uncompress(const void *src, size32_t &sz)
        {
        IExpander *expander = NULL;
        void *uncompressedValue = NULL;
        try { memcpy(&sz, src, sizeof(size32_t)); assertex(sz); expander = createLZWExpander(); src = ((const char *)src) + sizeof(size32_t); uncompressedValue = malloc(sz); assertex(uncompressedValue); expander->init(src); expander->expand(uncompressedValue); expander->Release(); return uncompressedValue; }

        catch (...)

        { if (expander) expander->Release(); if (uncompressedValue) free(uncompressedValue); throw; }

        }

        Attachments

          Activity

            People

            • Assignee:
              richardkchapman Richard Chapman
              Reporter:
              linuxsc Silviu Chitroceanu
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: