From 62d1562669676641613f31f9949008b73d56b458 Mon Sep 17 00:00:00 2001 From: Tai Vuong Date: Tue, 7 Nov 2017 15:40:40 -0500 Subject: Fix memory leak, ducking bug on policy, close stream --- ahl-binding/ahl-deviceenum.c | 50 ++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 23 deletions(-) (limited to 'ahl-binding/ahl-deviceenum.c') diff --git a/ahl-binding/ahl-deviceenum.c b/ahl-binding/ahl-deviceenum.c index f672417..b5b2a46 100644 --- a/ahl-binding/ahl-deviceenum.c +++ b/ahl-binding/ahl-deviceenum.c @@ -203,31 +203,35 @@ EndpointInfoT * InitEndpointInfo() return pEndpointInfo; } -void TermEndpointInfo( EndpointInfoT * out_pEndpointInfo ) +void TermEndpointInfo( gpointer data ) { + EndpointInfoT * out_pEndpointInfo = (EndpointInfoT *)data; #define SAFE_FREE(__ptr__) if(__ptr__) g_free(__ptr__); __ptr__ = NULL; - SAFE_FREE(out_pEndpointInfo->gsDeviceName); - SAFE_FREE(out_pEndpointInfo->gsDeviceDomain); - SAFE_FREE(out_pEndpointInfo->pRoleName); - SAFE_FREE(out_pEndpointInfo->gsDeviceURI); - SAFE_FREE(out_pEndpointInfo->gsHALAPIName); - SAFE_FREE(out_pEndpointInfo->gsDisplayName); - - if (out_pEndpointInfo->pPropTable) { - // Free json_object for all property values - GHashTableIter iter; - gpointer key, value; - g_hash_table_iter_init (&iter, out_pEndpointInfo->pPropTable); - while (g_hash_table_iter_next (&iter, &key, &value)) - { - if (value) - json_object_put(value); - } - g_hash_table_remove_all(out_pEndpointInfo->pPropTable); - g_hash_table_destroy(out_pEndpointInfo->pPropTable); - out_pEndpointInfo->pPropTable = NULL; - } - // GLib automatically frees item when removed from the array + if(out_pEndpointInfo) + { + SAFE_FREE(out_pEndpointInfo->gsDeviceName); + SAFE_FREE(out_pEndpointInfo->gsDeviceDomain); + SAFE_FREE(out_pEndpointInfo->pRoleName); + SAFE_FREE(out_pEndpointInfo->gsDeviceURI); + SAFE_FREE(out_pEndpointInfo->gsHALAPIName); + SAFE_FREE(out_pEndpointInfo->gsDisplayName); + + if (out_pEndpointInfo->pPropTable) { + // Free json_object for all property values + GHashTableIter iter; + gpointer key, value; + g_hash_table_iter_init (&iter, out_pEndpointInfo->pPropTable); + while (g_hash_table_iter_next (&iter, &key, &value)) + { + if (value) + json_object_put(value); + } + g_hash_table_remove_all(out_pEndpointInfo->pPropTable); + g_hash_table_destroy(out_pEndpointInfo->pPropTable); + out_pEndpointInfo->pPropTable = NULL; + } + g_slice_free (EndpointInfoT, out_pEndpointInfo); + } } // For a given audio role -- cgit 1.2.3-korg