Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753868AbcJNLPO (ORCPT ); Fri, 14 Oct 2016 07:15:14 -0400 Received: from mail.kernel.org ([198.145.29.136]:48594 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752589AbcJNLPF (ORCPT ); Fri, 14 Oct 2016 07:15:05 -0400 Date: Fri, 14 Oct 2016 08:13:59 -0300 From: Arnaldo Carvalho de Melo To: Nilay Vaish Cc: Stephane Eranian , Linux Kernel list , jolsa@redhat.com, peterz@infradead.org, mingo@elte.hu, anton@ozlabs.org, namhyung@kernel.org Subject: Re: [PATCH 1/9] perf/jit: improve error messages from JVMTI Message-ID: <20161014111359.GB12815@kernel.org> References: <1476356383-30100-1-git-send-email-eranian@google.com> <1476356383-30100-2-git-send-email-eranian@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.7.0 (2016-08-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1501 Lines: 40 Em Thu, Oct 13, 2016 at 03:05:40PM -0500, Nilay Vaish escreveu: > On 13 October 2016 at 05:59, Stephane Eranian wrote: > > +++ b/tools/perf/jvmti/libjvmti.c > > @@ -12,6 +12,17 @@ > > +static void print_error(jvmtiEnv *jvmti, const char *msg, jvmtiError ret) > > +{ > > + char *err_msg = NULL; > > + jvmtiError err; > > + err = (*jvmti)->GetErrorName(jvmti, ret, &err_msg); > > + if (err == JVMTI_ERROR_NONE) { > > + warnx("%s failed with %s", msg, err_msg); > > + (*jvmti)->Deallocate(jvmti, (unsigned char *)err_msg); > > + } > > +} > > Do we not need to release the memory for err_msg if the condition for > the 'if' statement evaluates to false? Is it that we are going to > kill the process, so no need to release the memory? I guess that print_error() is called only when an error was returned somewhere, that ret parameter, then if there was no error (JVMTI_ERROR_NONE) in translating that numeric code to an string, err_msg, it can then be used with warnx() (the main purpose of print_error()) and then deallocated. For err != JVMTI_ERROR_NONE it silently goes back to the caller that expected it to print something. I.e. probably it should have an else clause, something like: if (err == JVMTI_ERROR_NONE) { warnx("%s failed with %s", msg, err_msg); (*jvmti)->Deallocate(jvmti, (unsigned char *)err_msg); } else { warnx("%s failed with an unknown error %d", msg, (int)ret); } Stephane? - Arnaldo