[Live-devel] MediaSink / Memory leak

Brad O'Hearne brado at bighillsoftware.com
Tue Mar 6 14:08:36 PST 2012


All, 

I have a MediaSink subclass I have created. In the afterGettingFrame() method, I have the following code: 

  if (!fHaveWrittenFirstFrame) {
    // If we have PPS/SPS NAL units encoded in a "sprop parameter string", prepend these to the file:
    unsigned numSPropRecords;
    SPropRecord* sPropRecords = parseSPropParameterSets(fSPropParameterSetsStr, numSPropRecords);
    for (unsigned i = 0; i < numSPropRecords; ++i) {
      addData(start_code, 4, presentationTime);
      addData(sPropRecords[i].sPropBytes, sPropRecords[i].sPropLength, presentationTime);
    }
    delete[] sPropRecords;
    fHaveWrittenFirstFrame = True; // for next time
  }

This particular code snippet was taken directly from the Live555 H264VideoFileSink class implementation of its afterGettingFrame() method, so the exact code and usage context should be identical. 

Anyway, I have taken my app run it on Xcode, and this line pretty quickly crashes the app: 

    delete[] sPropRecords;

with the error that the "pointer being freed was not allocated". I then figured that there was something internal to the parseSPropParameterSets which might conditionally allocate sPropRecords. So I wrapped the delete in a conditional: 

    if (sPropRecords)
    {
        delete[] sPropRecords;
    }

The error was the same, and I confirmed in the debugger that sPropRecords was indeed a valid pointer. I then deleted out the offending delete line entirely, and ran the app. The app ran without crashing. However, when I profiled the app in Instruments, it reported a memory leak on this code line:

    SPropRecord* sPropRecords = parseSPropParameterSets(fSPropParameterSetsStr, numSPropRecords);

...which is obviously because there's no associated delete. So I believe it reasonable to conclude that there's a memory leak within this entity. My question -- does anyone have any insight into what the memory leak is and how to correct it? 

Thanks, 

Brad

Brad O'Hearne
Founder / Lead Developer
Big Hill Software LLC
http://www.bighillsoftware.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20120306/1c139815/attachment.html>


More information about the live-devel mailing list