From patchwork Tue Dec 4 13:29:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 152814 Delivered-To: patches@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp8069349ljp; Tue, 4 Dec 2018 05:29:58 -0800 (PST) X-Google-Smtp-Source: AFSGD/VJvqNXZlQJthv3JGzInlOuiPtnEj7Ym1zv4da//rXseGBJoA7j4N91K3AYJZebBncr+TNO X-Received: by 2002:a63:f74f:: with SMTP id f15mr16949523pgk.190.1543930198237; Tue, 04 Dec 2018 05:29:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543930198; cv=none; d=google.com; s=arc-20160816; b=wUo5n3a19N3i8YNQ3xq2Hoyk2DTj5lHHuXzav6u3gdS/YTljIxNc7isPKyg+6tcVbF pLFA3iKQzDdJ1gngdi14tx91zo67ru9GBSNdBsQnPjDFh41j65I81NdD0poDt2CnUqQl STl5wijF1/HXSqV75bwKAO1USPMYkkhC4mj0wT28vQHgNfwF9jNSuMjQ2aEmEGQizgoF Kj2pmx3iXlxoqh/nyxD6sg9mldJCYGpKqnSVVS8KD8IDg8U72ksyR/SNMwfQw3kfItCr 5oHA/6E6yCgA79iDcjcRO9QnBXJyzPzxa6GbdQ7uH5PSUB3sL+h3UMZa40+E7oYlIHDA FJOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=tgeGFH4aZVMT8632qLLPuEGDel/p8eo3fIWvMbqVlg4=; b=DKdrIaMDPLvNKqt110uMfnXhYAGqp+fS2epvrbYC138nf2bBWMcHmdc+QW4oCoElne FWO3iiyYS6/6JPxLSljJ8zKxKHJdvKSRO+ne5Vdw9bNHK6SKUNlZg1chEqo1142toueA Z6Z+hoKnvQso6kmLAdaiRLjRyrZEUudShFtqEhPV/jjr7d3MgZr9Ly6wWGPqrjlYufPC PnaJPFEl3uiWcN8aa3GIwdOBAqUytELWLyaeVM+tRYN1nh+0cheEYk0tWUTSRPMVeAft SIGU5llpBmu3aef7oXZQezGeGt4uf76KszgtGAghLdBXt78Z2tzidP9/plWwPBa55iLD NXvQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by mx.google.com with ESMTPS id q14si15449634pgf.47.2018.12.04.05.29.57 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Dec 2018 05:29:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) client-ip=2001:8b0:1d0::2; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1gUAlt-0008Bm-Iw; Tue, 04 Dec 2018 13:29:53 +0000 From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: patches@linaro.org Subject: [PATCH 1/5] target/arm: Free name string in ARMCPRegInfo hashtable entries Date: Tue, 4 Dec 2018 13:29:48 +0000 Message-Id: <20181204132952.2601-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181204132952.2601-1-peter.maydell@linaro.org> References: <20181204132952.2601-1-peter.maydell@linaro.org> MIME-Version: 1.0 When we add a new entry to the ARMCPRegInfo hash table in add_cpreg_to_hashtable(), we allocate memory for tehe ARMCPRegInfo struct itself, and we also g_strdup() the name string. So the hashtable's value destructor function must free the name string as well as the struct. Spotted by clang's leak sanitizer. The leak here is a small one-off leak at startup, because we don't support CPU hotplug, and so the only time when we destroy hash table entries is for the case where ARM_CP_OVERRIDE means we register a wildcard entry and then override it later. Signed-off-by: Peter Maydell --- target/arm/cpu.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) -- 2.19.2 Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 60411f6bfe0..b84a6c0e678 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -642,6 +642,20 @@ uint64_t arm_cpu_mp_affinity(int idx, uint8_t clustersz) return (Aff1 << ARM_AFF1_SHIFT) | Aff0; } +static void cpreg_hashtable_data_destroy(gpointer data) +{ + /* + * Destroy function for cpu->cp_regs hashtable data entries. + * We must free the name string because it was g_strdup()ed in + * add_cpreg_to_hashtable(). It's OK to cast away the 'const' + * from r->name because we know we definitely allocated it. + */ + ARMCPRegInfo *r = data; + + g_free((void *)r->name); + g_free(r); +} + static void arm_cpu_initfn(Object *obj) { CPUState *cs = CPU(obj); @@ -649,7 +663,7 @@ static void arm_cpu_initfn(Object *obj) cs->env_ptr = &cpu->env; cpu->cp_regs = g_hash_table_new_full(g_int_hash, g_int_equal, - g_free, g_free); + g_free, cpreg_hashtable_data_destroy); QLIST_INIT(&cpu->pre_el_change_hooks); QLIST_INIT(&cpu->el_change_hooks);