[nvptx, libgomp] Fix memleak in GOMP_OFFLOAD_fini_device

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.

From-SVN: r268237
This commit is contained in:
Tom de Vries 2019-01-24 14:12:19 +00:00 committed by Tom de Vries
parent 0e2eb6abeb
commit 738c56d410
2 changed files with 11 additions and 0 deletions

View 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

View 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;
}