]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[nvptx, libgomp] Fix memleak in GOMP_OFFLOAD_fini_device
authorvries <vries@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 24 Jan 2019 14:12:19 +0000 (14:12 +0000)
committervries <vries@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 24 Jan 2019 14:12:19 +0000 (14:12 +0000)
I wrote a test-case:
...
int
main (void)
{
  for (unsigned i = 0; i < 128; ++i)
    {
      acc_init (acc_device_nvidia);
      acc_shutdown (acc_device_nvidia);
    }

  return 0;
}
...
and ran it under valgrind.  The only leak location reported with a frequency
of 128, was the allocation of ptx_devices in nvptx_init.

Fix this by freeing ptx_devices in GOMP_OFFLOAD_fini_device, once
instantiated_devices drops to 0.

2019-01-24  Tom de Vries  <tdevries@suse.de>

* plugin/plugin-nvptx.c (GOMP_OFFLOAD_fini_device): Free ptx_devices
once instantiated_devices drops to 0.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@268237 138bc75d-0d04-0410-961f-82ee72b054a4

libgomp/ChangeLog
libgomp/plugin/plugin-nvptx.c

index 660fc924c7e3d7278d0d24600cad467237ce5234..fb694020dcdde809f4dfab1040a9d9e7a589586e 100644 (file)
@@ -1,3 +1,8 @@
+2019-01-24  Tom de Vries  <tdevries@suse.de>
+
+       * plugin/plugin-nvptx.c (GOMP_OFFLOAD_fini_device): Free ptx_devices
+       once instantiated_devices drops to 0.
+
 2019-01-23  Tom de Vries  <tdevries@suse.de>
 
        PR target/PR88946
index ff90b67cb866d277c19432aa75ccbc86e15a97a8..387e7cc6dd3240d0b9b990650e4ee36a98635697 100644 (file)
@@ -1936,6 +1936,12 @@ GOMP_OFFLOAD_fini_device (int n)
       instantiated_devices--;
     }
 
+  if (instantiated_devices == 0)
+    {
+      free (ptx_devices);
+      ptx_devices = NULL;
+    }
+
   pthread_mutex_unlock (&ptx_dev_lock);
   return true;
 }