From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29122 invoked by alias); 29 Jun 2007 03:36:25 -0000 Received: (qmail 29114 invoked by uid 22791); 29 Jun 2007 03:36:24 -0000 X-Spam-Check-By: sourceware.org Received: from viper.snap.net.nz (HELO viper.snap.net.nz) (202.37.101.8) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 29 Jun 2007 03:36:21 +0000 Received: from kahikatea.snap.net.nz (207.61.255.123.dynamic.snap.net.nz [123.255.61.207]) by viper.snap.net.nz (Postfix) with ESMTP id 178E33D9D75; Fri, 29 Jun 2007 15:36:18 +1200 (NZST) Received: by kahikatea.snap.net.nz (Postfix, from userid 1000) id 901BF8FBF6; Fri, 29 Jun 2007 15:36:08 +1200 (NZST) From: Nick Roberts MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <18052.32294.978000.582803@kahikatea.snap.net.nz> Date: Fri, 29 Jun 2007 04:32:00 -0000 To: msnyder@sonic.net Cc: gdb-patches@sourceware.org Subject: Re: [patch] memory leak, mi-cmd-var In-Reply-To: <24204.12.7.175.2.1183085800.squirrel@webmail.sonic.net> References: <24204.12.7.175.2.1183085800.squirrel@webmail.sonic.net> X-Mailer: VM 7.19 under Emacs 22.1.50.9 X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2007-06/txt/msg00520.txt.bz2 > 'nother one from Coverity. > > 2007-06-28 Michael Snyder > > * mi/mi-cmd-var.c (mi_cmd_var_set_format): Free strduped memory > (Coverity). Also take the opportunity to call error earlier > (before strdup). I don't see why the string has to be duplicated in the first place or how argv[1] could be NULL. Why not just: *** mi-cmd-var.c 14 Jun 2007 10:12:15 +1200 1.33 --- mi-cmd-var.c 29 Jun 2007 15:35:10 +1200 *************** mi_cmd_var_set_format (char *command, ch *** 209,217 **** if (var == NULL) error (_("mi_cmd_var_set_format: Variable object not found")); ! formspec = xstrdup (argv[1]); ! if (formspec == NULL) ! error (_("mi_cmd_var_set_format: Must specify the format as: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\"")); len = strlen (formspec); --- 209,215 ---- if (var == NULL) error (_("mi_cmd_var_set_format: Variable object not found")); ! formspec = argv[1]; len = strlen (formspec); > Index: mi/mi-cmd-var.c > =================================================================== > RCS file: /cvs/src/src/gdb/mi/mi-cmd-var.c,v > retrieving revision 1.33 > diff -p -r1.33 mi-cmd-var.c > *** mi/mi-cmd-var.c 13 Jun 2007 19:08:47 -0000 1.33 > --- mi/mi-cmd-var.c 29 Jun 2007 02:52:39 -0000 > *************** mi_cmd_var_set_format (char *command, ch > *** 209,218 **** > if (var == NULL) > error (_("mi_cmd_var_set_format: Variable object not found")); > > ! formspec = xstrdup (argv[1]); > ! if (formspec == NULL) > error (_("mi_cmd_var_set_format: Must specify the format as: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\"")); > > len = strlen (formspec); > > if (strncmp (formspec, "natural", len) == 0) > --- 209,220 ---- > if (var == NULL) > error (_("mi_cmd_var_set_format: Variable object not found")); > > ! if (argv[1] == NULL) > error (_("mi_cmd_var_set_format: Must specify the format as: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\"")); > > + formspec = xstrdup (argv[1]); > + make_cleanup (xfree, formspec); > + > len = strlen (formspec); > > if (strncmp (formspec, "natural", len) == 0) -- Nick http://www.inet.net.nz/~nickrob