From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 532 invoked by alias); 27 Feb 2011 23:29:17 -0000 Received: (qmail 523 invoked by uid 22791); 27 Feb 2011 23:29:16 -0000 X-SWARE-Spam-Status: No, hits=-5.0 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp-outbound-1.vmware.com (HELO smtp-outbound-1.vmware.com) (65.115.85.69) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 27 Feb 2011 23:29:10 +0000 Received: from mailhost3.vmware.com (mailhost3.vmware.com [10.16.27.45]) by smtp-outbound-1.vmware.com (Postfix) with ESMTP id 976D31D009 for ; Sun, 27 Feb 2011 15:29:09 -0800 (PST) Received: from msnyder-server.eng.vmware.com (promd-2s-dhcp138.eng.vmware.com [10.20.124.138]) by mailhost3.vmware.com (Postfix) with ESMTP id 8B4A3CD94F for ; Sun, 27 Feb 2011 15:29:09 -0800 (PST) Message-ID: <4D6ADE45.5040705@vmware.com> Date: Sun, 27 Feb 2011 23:50:00 -0000 From: Michael Snyder User-Agent: Thunderbird 2.0.0.24 (X11/20101201) MIME-Version: 1.0 To: "gdb-patches@sourceware.org" Subject: [RFA] target.c/read_whatever_is_readable: fix memory leak Content-Type: multipart/mixed; boundary="------------080502030402080500050109" 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: 2011-02/txt/msg00862.txt.bz2 This is a multi-part message in MIME format. --------------080502030402080500050109 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 0 --------------080502030402080500050109 Content-Type: text/plain; name="read_whatever.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="read_whatever.txt" Content-length: 1194 2011-02-27 Michael Snyder * target.c (read_whatever_is_readable): Fix memory leak. Index: target.c =================================================================== RCS file: /cvs/src/src/gdb/target.c,v retrieving revision 1.275 diff -u -p -u -p -r1.275 target.c --- target.c 15 Feb 2011 17:22:21 -0000 1.275 +++ target.c 27 Feb 2011 23:27:16 -0000 @@ -1954,7 +1954,7 @@ read_whatever_is_readable (struct target ULONGEST begin, ULONGEST end, VEC(memory_read_result_s) **result) { - gdb_byte *buf = xmalloc (end-begin); + gdb_byte *buf = xmalloc (end - begin); ULONGEST current_begin = begin; ULONGEST current_end = end; int forward; @@ -1962,7 +1962,10 @@ read_whatever_is_readable (struct target /* If we previously failed to read 1 byte, nothing can be done here. */ if (end - begin <= 1) - return; + { + xfree (buf); + return; + } /* Check that either first or the last byte is readable, and give up if not. This heuristic is meant to permit reading accessible memory @@ -1981,6 +1984,7 @@ read_whatever_is_readable (struct target } else { + xfree (buf); return; } --------------080502030402080500050109--