More memory cleanup
authorhyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Tue, 10 Nov 2009 11:19:47 +0000 (11:19 +0000)
committerhyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Tue, 10 Nov 2009 11:19:47 +0000 (11:19 +0000)
git-svn-id: svn://svn.mplayerhq.hu/rtmpdump@42 400ebc74-4327-4243-bc38-086b20814532

rtmp.cpp
rtmpdump.cpp

index f88dbdea880db99ac4f4ccd1c5f3708b6d7252dd..3bd82dea00949dce12e37cb205f813aa75443f1f 100644 (file)
--- a/rtmp.cpp
+++ b/rtmp.cpp
@@ -1472,10 +1472,14 @@ bool CRTMP::ReadPacket(RTMPPacket &packet)
   if (nSize == 11)
     packet.m_nInfoField2 = ReadInt32LE(header+7);
 
-  if (packet.m_nBodySize > 0 && packet.m_body == NULL && !packet.AllocPacket(packet.m_nBodySize))
+  bool didAlloc = false;
+  if (packet.m_nBodySize > 0 && packet.m_body == NULL)
   {
-    Log(LOGDEBUG, "%s, failed to allocate packet", __FUNCTION__);
-    return false;
+    if (!packet.AllocPacket(packet.m_nBodySize)) {
+      Log(LOGDEBUG, "%s, failed to allocate packet", __FUNCTION__);
+      return false;
+    }
+    didAlloc = true;
   }
 
   int nToRead = packet.m_nBodySize - packet.m_nBytesRead;
@@ -1486,8 +1490,10 @@ bool CRTMP::ReadPacket(RTMPPacket &packet)
   if (ReadN(packet.m_body + packet.m_nBytesRead, nChunk) != nChunk)
   {
     Log(LOGERROR, "%s, failed to read RTMP packet body. len: %lu", __FUNCTION__, packet.m_nBodySize);
-    packet.m_body = NULL; // we dont want it deleted since its pointed to from the stored packets (m_vecChannelsIn)
-    packet.m_buffer = NULL;
+    if (!didAlloc) {
+      packet.m_body = NULL; // we dont want it deleted since its pointed to from the stored packets (m_vecChannelsIn)
+      packet.m_buffer = NULL;
+    }
     return false;  
   }
 
index da4bfaefae974a89ac80c232d87c8915dcfe2bc2..3f0b91d92d5c06bdca170a7b5206697935622504 100644 (file)
@@ -1237,12 +1237,8 @@ int main(int argc, char **argv)
                strcpy(tcUrl, str);
        }
 
-       int bufferSize = 1024*1024;
-       char *buffer = (char *)malloc(bufferSize);
        int first = 1;
 
-       memset(buffer, 0, bufferSize);
-
        // User defined seek offset
        if (dStartOffset > 0) {
                // Live stream