Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966904AbbLPTtm (ORCPT ); Wed, 16 Dec 2015 14:49:42 -0500 Received: from mail.kernel.org ([198.145.29.136]:48554 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966658AbbLPTtk (ORCPT ); Wed, 16 Dec 2015 14:49:40 -0500 Date: Wed, 16 Dec 2015 16:49:37 -0300 From: Arnaldo Carvalho de Melo To: "Wangnan (F)" Cc: Jiri Olsa , masami.hiramatsu.pt@hitachi.com, jolsa@kernel.org, linux-kernel@vger.kernel.org, pi3orama@163.com, lizefan@huawei.com, Namhyung Kim Subject: Re: [PATCH v5 02/14] perf tools: Prevent calling machine__delete() on non-allocated machine Message-ID: <20151216194937.GC19926@kernel.org> References: <1450089563-122430-1-git-send-email-wangnan0@huawei.com> <1450089563-122430-3-git-send-email-wangnan0@huawei.com> <20151215123658.GC20514@krava.brq.redhat.com> <5670C04E.3080802@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5670C04E.3080802@huawei.com> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1744 Lines: 56 Em Wed, Dec 16, 2015 at 09:37:18AM +0800, Wangnan (F) escreveu: > > > On 2015/12/15 20:36, Jiri Olsa wrote: > >On Mon, Dec 14, 2015 at 10:39:11AM +0000, Wang Nan wrote: > > > >SNIP > > > >>@@ -137,12 +138,15 @@ void machine__exit(struct machine *machine) > >> void machine__delete(struct machine *machine) > >> { > >> machine__exit(machine); > >>- free(machine); > >>+ if (machine->allocated) > >>+ free(machine); > >>+ else > >>+ pr_warning("WARNING: delete a non-allocated machine. Skip.\n"); > >we used WARN_ONCE several times already in similar cases > > > >jirka > > Will switch to: > > @@ -136,13 +138,13 @@ void machine__exit(struct machine *machine) > > void machine__delete(struct machine *machine) > { > - machine__exit(machine); Better keep the above. And I wonder if we would go on sprinkling these kinds of checks for all classes we have :-\ I think this is a job for some static analisys tool, that or we figure out a way to find out if an address is for a stack or heap and use that instead, and in a bpf based tool, perhaps, one that would hook into all *__delete() tools and check if the object it is using should or not be in fact free()ed. I could think about hooking __new*() calls, hashing the return value, then at __delete() time check it, for instance. - Arnaldo > - free(machine); > + WARN_ONCE((machine->allocated ? free(machine), 0 : -1), > + "WARNING: deleting a non-allocated machine. Skip.\n"); > } > > Thank you. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/