From f2fb5eb58ae50bb35f2d0ae2673a596adc06cb00 Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期一, 28 十月 2019 13:17:01 +0800
Subject: [PATCH] bug fixed gb mem leak

---
 csrc/thirdparty/gb28181/include/PsToEs.hpp |   30 ++++++++++++++++++++++++------
 1 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/csrc/thirdparty/gb28181/include/PsToEs.hpp b/csrc/thirdparty/gb28181/include/PsToEs.hpp
index 51f613a..88eb4d9 100644
--- a/csrc/thirdparty/gb28181/include/PsToEs.hpp
+++ b/csrc/thirdparty/gb28181/include/PsToEs.hpp
@@ -67,6 +67,16 @@
 		while (!q.empty()) q.pop_front();
 		pthread_mutex_unlock(&mtx);
     }
+	
+	void clearAll(std::function<void(T)> fn){
+		pthread_mutex_lock(&mtx);
+		while (!q.empty()){
+			T value = q.front();
+			fn(value);
+			q.pop_front();
+		} 
+		pthread_mutex_unlock(&mtx);
+	}
 private:
     deque<T> q;
     pthread_mutex_t mtx;
@@ -87,7 +97,11 @@
 
 	~GB28181API(){
 		printf("GB28181API end!\n");
-		m_rtpQueue.clearAll();
+		// m_rtpQueue.clearAll();
+		m_rtpQueue.clearAll([](frameBuffInfo *info){
+			delete[] info->buff;
+			delete info;
+		});
 		deleteCamera();
 	}
 
@@ -174,20 +188,24 @@
 		}
 	}
 
-	void addCamera(string &rtsp){
+	long addCamera(string &rtsp){
 //		long userdata = 1001;//
-		printf("RTSPSTREAM_Open\n");
 		handle = RTSPSTREAM_Open(rtsp.c_str(), streamCallBack, (long)this);
-//		return handle;
+		printf("RTSPSTREAM_Open, handle:%ld \n", handle);
+		return handle;
 	}
 
 	void deleteCamera(){
 		printf("RTSPSTREAM_Close\n");
-		RTSPSTREAM_Close(handle);
+		if(handle != -1){
+			RTSPSTREAM_Close(handle);
+		}
+
+		handle = -1;
 	}	
 private:
 	MyQueue<frameBuffInfo *> m_rtpQueue;
-	long handle;
+	long handle = -1;
 };
 
 

--
Gitblit v1.8.0