From patchwork Thu Jan 24 14:14:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 1030475 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-494667-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="UbWlBHfM"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43lkfn2Jf4z9s4s for ; Fri, 25 Jan 2019 01:14:08 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=Oa7smd8uEHmVQkJMOHzGLDm/OScTveJtD3A2kahU3Iqf0Usjn3 +9cFq3P7FnSHodl8h5uElb52Vn92iB0rrp9ErGJVzjM9olVHRTh1AsTWuIShbQcp sySgbBB9fa1B4C7grJQUkPKuhFi59+QmAcgpWcZ2cW3HpfHiOna7vruj4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=eS5IWClHzKVB/us0LuNT3qhIsAo=; b=UbWlBHfMjs0EYuiMf39H vi57PXo3nuLC4hPFh3zK+nxicVVM490NjmqOU9I1mAT+lsTasHfIHBWsVw1W5OlE QCgXk/wjWzJoVuc2QM1q9kLfCsq5zWlyBWBE7k5pqFdaTYZbwtznGFelloQqYByL ZKIHniadxRB43D8484hp4Ac= Received: (qmail 100129 invoked by alias); 24 Jan 2019 14:14:00 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 100117 invoked by uid 89); 24 Jan 2019 14:13:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1205 X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 24 Jan 2019 14:13:56 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 3F970ACC8; Thu, 24 Jan 2019 14:13:54 +0000 (UTC) Date: Thu, 24 Jan 2019 15:14:25 +0100 From: Tom de Vries To: gcc-patches@gcc.gnu.org Cc: Thomas Schwinge Subject: [committed][nvptx, libgomp] Fix memleak in GOMP_OFFLOAD_fini_device Message-ID: <20190124141423.GA7822@delia> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-IsSubscribed: yes 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 * 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; }