Browse Source

Merge pull request #774 from DarthBo/fix/close_nice_agent

libnice: close agent before releasing it
Paul-Louis Ageneau 2 years ago
parent
commit
1bb91b8d14
2 changed files with 11 additions and 2 deletions
  1. 10 1
      src/impl/icetransport.cpp
  2. 1 1
      src/impl/icetransport.hpp

+ 10 - 1
src/impl/icetransport.cpp

@@ -344,6 +344,15 @@ void IceTransport::LogCallback(juice_log_level_t level, const char *message) {
 
 #else // USE_NICE == 1
 
+static void closeNiceAgentCallback(GObject *niceAgent, GAsyncResult *, gpointer) {
+	g_object_unref(niceAgent);
+}
+
+static void closeNiceAgent(NiceAgent *niceAgent) {
+	// close the agent to prune alive TURN refreshes, before releasing it
+	nice_agent_close_async(niceAgent, closeNiceAgentCallback, nullptr);
+}
+
 IceTransport::IceTransport(const Configuration &config, candidate_callback candidateCallback,
                            state_callback stateChangeCallback,
                            gathering_state_callback gatheringStateChangeCallback)
@@ -377,7 +386,7 @@ IceTransport::IceTransport(const Configuration &config, candidate_callback candi
 	        g_main_loop_get_context(mMainLoop.get()),
 	        NICE_COMPATIBILITY_RFC5245, // RFC 5245 was obsoleted by RFC 8445 but this should be OK
 	        flags),
-	    g_object_unref);
+	    closeNiceAgent);
 
 	if (!mNiceAgent)
 		throw std::runtime_error("Failed to create the nice agent");

+ 1 - 1
src/impl/icetransport.hpp

@@ -84,7 +84,7 @@ private:
 	static void LogCallback(juice_log_level_t level, const char *message);
 #else
 	uint32_t mStreamId = 0;
-	unique_ptr<NiceAgent, void (*)(gpointer)> mNiceAgent;
+	unique_ptr<NiceAgent, void (*)(NiceAgent *)> mNiceAgent;
 	unique_ptr<GMainLoop, void (*)(GMainLoop *)> mMainLoop;
 	std::thread mMainLoopThread;
 	guint mTimeoutId = 0;