From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16255 invoked by alias); 8 Aug 2007 18:32:42 -0000 Received: (qmail 16141 invoked by uid 22791); 8 Aug 2007 18:32:42 -0000 X-Spam-Check-By: sourceware.org Received: from a.mail.sonic.net (HELO a.mail.sonic.net) (64.142.16.245) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 08 Aug 2007 18:32:40 +0000 Received: from webmail.sonic.net (b.webmail.sonic.net [64.142.100.148]) by a.mail.sonic.net (8.13.8.Beta0-Sonic/8.13.7) with ESMTP id l78IWcoW002668; Wed, 8 Aug 2007 11:32:38 -0700 Received: from 12.7.175.2 (SquirrelMail authenticated user msnyder) by webmail.sonic.net with HTTP; Wed, 8 Aug 2007 11:32:38 -0700 (PDT) Message-ID: <15524.12.7.175.2.1186597958.squirrel@webmail.sonic.net> In-Reply-To: References: <13153.12.7.175.2.1186284546.squirrel@webmail.sonic.net> Date: Wed, 08 Aug 2007 18:32:00 -0000 Subject: Re: [patch] target_read_string, potential memory leak. From: msnyder@sonic.net To: "Jim Blandy" Cc: msnyder@sonic.net, gdb-patches@sourceware.org User-Agent: SquirrelMail/1.4.9a MIME-Version: 1.0 Content-Type: multipart/mixed;boundary="----=_20070808113238_17591" 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-08/txt/msg00153.txt.bz2 ------=_20070808113238_17591 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Content-length: 345 > > msnyder@sonic.net writes: >> OK -- it would be pretty stupid to call target_read_string without >> passing it a buffer, but if we're going to check it for null... > > I don't think the contract for target_read_string permits STRING to be > null. I think either the test should go, or we should add a > gdb_assert (string). Agreed. Thus? ------=_20070808113238_17591 Content-Type: text/plain; name="target_string.txt" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="target_string.txt" Content-length: 939 Index: target.c =================================================================== RCS file: /cvs/src/src/gdb/target.c,v retrieving revision 1.145 diff -p -r1.145 target.c *** target.c 24 Jul 2007 12:49:24 -0000 1.145 --- target.c 8 Aug 2007 18:31:57 -0000 *************** target_read_string (CORE_ADDR memaddr, c *** 919,924 **** --- 919,926 ---- char *bufptr; unsigned int nbytes_read = 0; + gdb_assert (string); + /* Small for testing. */ buffer_allocated = 4; buffer = xmalloc (buffer_allocated); *************** target_read_string (CORE_ADDR memaddr, c *** 968,977 **** nbytes_read += tlen; } done: if (errnop != NULL) *errnop = errcode; - if (string != NULL) - *string = buffer; return nbytes_read; } --- 970,978 ---- nbytes_read += tlen; } done: + *string = buffer; if (errnop != NULL) *errnop = errcode; return nbytes_read; } ------=_20070808113238_17591--