Hi, 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. Committed to trunk. Thanks, - Tom [nvptx, libgomp] Fix memleak in GOMP_OFFLOAD_fini_device 2019-01-24 Tom de Vries <tdevr...@suse.de> * plugin/plugin-nvptx.c (GOMP_OFFLOAD_fini_device): Free ptx_devices once instantiated_devices drops to 0. --- libgomp/plugin/plugin-nvptx.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libgomp/plugin/plugin-nvptx.c b/libgomp/plugin/plugin-nvptx.c index ff90b67cb86..387e7cc6dd3 100644 --- a/libgomp/plugin/plugin-nvptx.c +++ b/libgomp/plugin/plugin-nvptx.c @@ -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; }