From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Hui Zhu <teawater@gmail.com>
Cc: Thiago Jung Bauermann <bauerman@br.ibm.com>, gdb-patches@sourceware.org
Subject: Re: [patch]: Fix memory leak of c-exp.y
Date: Tue, 24 Jun 2008 14:04:00 -0000 [thread overview]
Message-ID: <20080624133540.GA1948@host0.dyn.jankratochvil.net> (raw)
In-Reply-To: <daef60380806232332n429917efu4eec3c7ca1731987@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 556 bytes --]
On Tue, 24 Jun 2008 08:32:44 +0200, teawater wrote:
> ChangeLog:
> 2008-06-21 Hui Zhu <teawater@gmail.com>
> * gdb/c-exp.y: Fix memory leak of function parse_number
Agreed with the fix just IMO the block of code needs more cleanups. [attached]
The leak was brought in by:
http://sourceware.org/ml/gdb-patches/2007-10/msg00395.html
Just please check the GNU Coding Standards document for the ChangeLog style, it
should have been more like:
2008-06-21 Hui Zhu <teawater@gmail.com>
* c-exp.y (parse_number): Fix a memory leak.
Thanks,
Jan
[-- Attachment #2: gdb-c-exp-dfp-leaketc.patch --]
[-- Type: text/plain, Size: 2525 bytes --]
2008-06-24 Jan Kratochvil <jan.kratochvil@redhat.com>
Fix a memory leak found by Hui Zhu <teawater@gmail.com>.
* c-exp.y (parse_number): Move the S and SAVED_CHAR initialization
after the DECFLOAT detection to fix a memory leak. Remove the
redundant NUM initialization. Protect the DECFLOAT detection memory
access before the P block. Restore the P memory content for the
DECFLOAT detection.
--- ./gdb/c-exp.y 9 Jun 2008 19:25:14 -0000 1.45
+++ ./gdb/c-exp.y 24 Jun 2008 13:03:26 -0000
@@ -1118,45 +1118,46 @@ parse_number (p, len, parsed_float, puti
if (parsed_float)
{
/* It's a float since it contains a point or an exponent. */
- char *s = malloc (len);
- int num = 0; /* number of tokens scanned by scanf */
- char saved_char = p[len];
-
- p[len] = 0; /* null-terminate the token */
+ char *s;
+ int num; /* number of tokens scanned by scanf */
+ char saved_char;
/* If it ends at "df", "dd" or "dl", take it as type of decimal floating
point. Return DECFLOAT. */
- if (p[len - 2] == 'd' && p[len - 1] == 'f')
+ if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'f')
{
p[len - 2] = '\0';
putithere->typed_val_decfloat.type
= builtin_type (current_gdbarch)->builtin_decfloat;
decimal_from_string (putithere->typed_val_decfloat.val, 4, p);
- p[len] = saved_char;
- return (DECFLOAT);
+ p[len - 2] = 'd';
+ return DECFLOAT;
}
- if (p[len - 2] == 'd' && p[len - 1] == 'd')
+ if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'd')
{
p[len - 2] = '\0';
putithere->typed_val_decfloat.type
= builtin_type (current_gdbarch)->builtin_decdouble;
decimal_from_string (putithere->typed_val_decfloat.val, 8, p);
- p[len] = saved_char;
- return (DECFLOAT);
+ p[len - 2] = 'd';
+ return DECFLOAT;
}
- if (p[len - 2] == 'd' && p[len - 1] == 'l')
+ if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'l')
{
p[len - 2] = '\0';
putithere->typed_val_decfloat.type
= builtin_type (current_gdbarch)->builtin_declong;
decimal_from_string (putithere->typed_val_decfloat.val, 16, p);
- p[len] = saved_char;
- return (DECFLOAT);
+ p[len - 2] = 'd';
+ return DECFLOAT;
}
+ s = malloc (len);
+ saved_char = p[len];
+ p[len] = 0; /* null-terminate the token */
num = sscanf (p, "%" DOUBLEST_SCAN_FORMAT "%s",
&putithere->typed_val_float.dval, s);
p[len] = saved_char; /* restore the input stream */
next prev parent reply other threads:[~2008-06-24 13:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-24 12:32 teawater
2008-06-24 14:04 ` Jan Kratochvil [this message]
2008-06-25 12:32 ` teawater
2008-06-25 13:11 ` Joel Brobecker
2008-06-25 13:40 ` Daniel Jacobowitz
-- strict thread matches above, loose matches on Subject: below --
2008-06-21 17:21 teawater
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080624133540.GA1948@host0.dyn.jankratochvil.net \
--to=jan.kratochvil@redhat.com \
--cc=bauerman@br.ibm.com \
--cc=gdb-patches@sourceware.org \
--cc=teawater@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox