diff mbox

[libdrm,3/3] amdgpu: Destroy fd_hash table when the last device is removed.

Message ID 20180518170007.2847-3-jan.vesely@rutgers.edu (mailing list archive)
State New, archived
Headers show

Commit Message

Jan Vesely May 18, 2018, 5 p.m. UTC
Fixes memory leak on module unload.
Analogous to mesa commit of the same name.
Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
---
 amdgpu/amdgpu_device.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Jan Vesely May 24, 2018, 5:04 p.m. UTC | #1
On Fri, 2018-05-18 at 13:00 -0400, Jan Vesely wrote:
> Fixes memory leak on module unload.
> Analogous to mesa commit of the same name.
> Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
> ---
>  amdgpu/amdgpu_device.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/amdgpu/amdgpu_device.c b/amdgpu/amdgpu_device.c
> index e23dd3b3..34ac95b8 100644
> --- a/amdgpu/amdgpu_device.c
> +++ b/amdgpu/amdgpu_device.c
> @@ -128,6 +128,10 @@ static void amdgpu_device_free_internal(amdgpu_device_handle dev)
>  {
>  	pthread_mutex_lock(&fd_mutex);
>  	util_hash_table_remove(fd_tab, UINT_TO_PTR(dev->fd));
> +	if (util_hash_table_count(fd_tab) == 0) {
> +		util_hash_table_destroy(fd_tab);
> +		fd_tab = NULL;
> +	}
>  	close(dev->fd);
>  	if ((dev->flink_fd >= 0) && (dev->fd != dev->flink_fd))
>  		close(dev->flink_fd);

gentle ping.

Jan
diff mbox

Patch

diff --git a/amdgpu/amdgpu_device.c b/amdgpu/amdgpu_device.c
index e23dd3b3..34ac95b8 100644
--- a/amdgpu/amdgpu_device.c
+++ b/amdgpu/amdgpu_device.c
@@ -128,6 +128,10 @@  static void amdgpu_device_free_internal(amdgpu_device_handle dev)
 {
 	pthread_mutex_lock(&fd_mutex);
 	util_hash_table_remove(fd_tab, UINT_TO_PTR(dev->fd));
+	if (util_hash_table_count(fd_tab) == 0) {
+		util_hash_table_destroy(fd_tab);
+		fd_tab = NULL;
+	}
 	close(dev->fd);
 	if ((dev->flink_fd >= 0) && (dev->fd != dev->flink_fd))
 		close(dev->flink_fd);