Opened 16 years ago

Last modified 16 years ago

#1103 closed defect (fixed)

Memory Leak in OGRStyleTool::GetStyleString

Reported by: rlcave3rd@… Owned by: warmerdam
Priority: high Milestone:
Component: OGR_SF Version: unspecified
Severity: normal Keywords:


I found this memory leak in GDAL 1.3.1.  Here is the patch I used (my changes
are marked with ">>" in the left margin):

const char *OGRStyleTool::GetStyleString( OGRStyleParamId *pasStyleParam ,
                            OGRStyleValue *pasStyleValue, int nSize)
    int i;
    GBool bFound;

    char *pszCurrent = NULL;
    const char *pszClass;
    pszCurrent = (char *)CPLCalloc(nSize, 20 * sizeof(char));

<clipped for brevity>


        m_pszStyleString = CPLStrdup(pszCurrent);

>>      CPLFree(pszCurrent); // Fixed memory leak

        m_bModified = FALSE;
    return m_pszStyleString;

Change History (1)

comment:1 by warmerdam, 16 years ago

Memory leak fixed.  I made szCurrent a stack string instead of allocating
it on the heap.  Unfortunately, I don't seem to have any code that uses
this method, so I wasn't able to properly test it. 

Note: See TracTickets for help on using tickets.