shithub: openh264

Download patch

ref: b5f1460dd1be3ee23468daf8b46724e1f1dc0126
parent: 955fce60a1cfcbd66a778350fc4b6d8e54ea946f
author: pengyanhai <[email protected]>
date: Mon Nov 9 06:52:11 EST 2015

Tear down the OpenH264 encoder and decoder properly to avoid potential crash and memory leak

--- a/module/gmp-openh264.cpp
+++ b/module/gmp-openh264.cpp
@@ -368,9 +368,24 @@
 
  private:
   virtual ~OpenH264VideoEncoder() {
-    worker_thread_->Join();
+    // Tear down the internal encoder
+    TearDownEncoder();
   }
 
+   void TearDownEncoder() {
+     // Stop the worker thread first
+     if (worker_thread_) {
+       worker_thread_->Join();
+       worker_thread_ = nullptr;
+     }
+
+     // Destroy OpenH264 encoder
+     if (encoder_) {
+       WelsDestroySVCEncoder(encoder_);
+       encoder_ = nullptr;
+     }
+   }
+
   void Error (GMPErr error) {
     if (callback_) {
       callback_->Error (error);
@@ -727,8 +742,23 @@
 
  private:
   virtual ~OpenH264VideoDecoder() {
+    // Tear down the internal decoder
+    TearDownDecoder();
   }
 
+  void TearDownDecoder() {
+    // Stop the worker thread first
+    if (worker_thread_) {
+      worker_thread_->Join();
+      worker_thread_ = nullptr;
+    }
+
+    // Destroy OpenH264 decoder
+    if (decoder_) {
+      WelsDestroyDecoder(decoder_);
+      decoder_ = nullptr;
+    }
+  }
   void Error (GMPErr error) {
     if (callback_) {
       callback_->Error (error);