winsys/radeon: Destroy fd_hash table when the last winsys is removed.
authorJan Vesely <jan.vesely@rutgers.edu>
Tue, 8 May 2018 05:39:04 +0000 (01:39 -0400)
committerJan Vesely <jan.vesely@rutgers.edu>
Thu, 10 May 2018 09:12:48 +0000 (05:12 -0400)
Fixes memory leak on module unload.
v2: Use util_hash_table helper function

CC: <mesa-stable@lists.freedesktop.org>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
src/gallium/winsys/radeon/drm/radeon_drm_winsys.c

index 3ee243adbccbd5a0c0da9e796aee02faa422a65c..253dd4e2eb6e3262d3a87f622dec6ca334757abf 100644 (file)
@@ -719,8 +719,13 @@ static bool radeon_winsys_unref(struct radeon_winsys *ws)
     mtx_lock(&fd_tab_mutex);
 
     destroy = pipe_reference(&rws->reference, NULL);
-    if (destroy && fd_tab)
+    if (destroy && fd_tab) {
         util_hash_table_remove(fd_tab, intptr_to_pointer(rws->fd));
+        if (util_hash_table_count(fd_tab) == 0) {
+           util_hash_table_destroy(fd_tab);
+           fd_tab = NULL;
+        }
+    }
 
     mtx_unlock(&fd_tab_mutex);
     return destroy;