winsys/amdgpu: Destroy dev_hash table when the last winsys is removed.
authorJan Vesely <jan.vesely@rutgers.edu>
Thu, 10 May 2018 22:29:13 +0000 (18:29 -0400)
committerJan Vesely <jan.vesely@rutgers.edu>
Fri, 11 May 2018 03:23:50 +0000 (23:23 -0400)
Fixes memory leak on module unload.

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

index f4bbd3e7324478f6f8c62634a3da249c7ab94d72..84d8ca6fcf3e8dd64efaf4587c748dd317023830 100644 (file)
@@ -220,8 +220,13 @@ static bool amdgpu_winsys_unref(struct radeon_winsys *rws)
    simple_mtx_lock(&dev_tab_mutex);
 
    destroy = pipe_reference(&ws->reference, NULL);
-   if (destroy && dev_tab)
+   if (destroy && dev_tab) {
       util_hash_table_remove(dev_tab, ws->dev);
+      if (util_hash_table_count(dev_tab) == 0) {
+         util_hash_table_destroy(dev_tab);
+         dev_tab = NULL;
+      }
+   }
 
    simple_mtx_unlock(&dev_tab_mutex);
    return destroy;