Bug 981966 - fix OggWriter memory leak; r=kinetik,f=mccr8
authorNathan Froyd <froydnj@mozilla.com>
Tue, 11 Mar 2014 14:17:02 -0400
changeset 173099 89b07f1c81ee16e9f9460bb9cfc4c5efcb6a5d43
parent 173098 a1a9976d954e0b088a86c302773dfe0e528b0932
child 173100 53ce2fc68c7ea96cf06b9ff19c2faa260b9353ce
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerskinetik
bugs981966
milestone30.0a1
Bug 981966 - fix OggWriter memory leak; r=kinetik,f=mccr8
content/media/ogg/OggWriter.cpp
content/media/ogg/OggWriter.h
--- a/content/media/ogg/OggWriter.cpp
+++ b/content/media/ogg/OggWriter.cpp
@@ -17,16 +17,24 @@ namespace mozilla {
 
 OggWriter::OggWriter() : ContainerWriter()
 {
   if (NS_FAILED(Init())) {
     LOG("ERROR! Fail to initialize the OggWriter.");
   }
 }
 
+OggWriter::~OggWriter()
+{
+  if (mInitialized) {
+    ogg_stream_clear(&mOggStreamState);
+  }
+  // mPacket's data was always owned by us, no need to ogg_packet_clear.
+}
+
 nsresult
 OggWriter::Init()
 {
   MOZ_ASSERT(!mInitialized);
 
   // The serial number (serialno) should be a random number, for the current
   // implementation where the output file contains only a single stream, this
   // serialno is used to differentiate between files.
--- a/content/media/ogg/OggWriter.h
+++ b/content/media/ogg/OggWriter.h
@@ -17,16 +17,17 @@ namespace mozilla {
  * to the Ogg stream.
  * For more details, please reference:
  * http://www.xiph.org/ogg/doc/libogg/encoding.html
  */
 class OggWriter : public ContainerWriter
 {
 public:
   OggWriter();
+  ~OggWriter();
 
   nsresult WriteEncodedTrack(const EncodedFrameContainer &aData,
                              uint32_t aFlags = 0) MOZ_OVERRIDE;
 
   nsresult GetContainerData(nsTArray<nsTArray<uint8_t> >* aOutputBufs,
                             uint32_t aFlags = 0) MOZ_OVERRIDE;
 
   // Check metadata type integrity and reject unacceptable track encoder.