Fix leak in mdebugread.c
Coverity points out that all the "continue;" statements in the switch case in parse_partial_symbols leak STABSTRING. This is because we only release STABSTRING at the end of the scope, with: if (stabstring && stabstring != debug_info->ss + fh->issBase + sh.iss) xfree (stabstring); but that bit of code is skipped if a case in the switch statement ends with "continue". Fix this by using gdb::unique_xmalloc_ptr to manage the heap-allocated version of 'stabsstring'. I don't know how to test this. gdb/ChangeLog: 2019-01-10 Pedro Alves <palves@redhat.com> * mdebugread.c (parse_partial_symbols): Use gdb::unique_xmalloc_ptr to manage heap-allocated 'stabsstring'.
This commit is contained in:
parent
da58495800
commit
36cb72375c
@ -1,3 +1,8 @@
|
|||||||
|
2019-01-10 Pedro Alves <palves@redhat.com>
|
||||||
|
|
||||||
|
* mdebugread.c (parse_partial_symbols): Use
|
||||||
|
gdb::unique_xmalloc_ptr to manage heap-allocated 'stabsstring'.
|
||||||
|
|
||||||
2019-01-10 Andrew Burgess <andrew.burgess@embecosm.com>
|
2019-01-10 Andrew Burgess <andrew.burgess@embecosm.com>
|
||||||
|
|
||||||
* linux-fork.c (scoped_switch_fork_info)
|
* linux-fork.c (scoped_switch_fork_info)
|
||||||
|
@ -2765,6 +2765,9 @@ parse_partial_symbols (minimal_symbol_reader &reader,
|
|||||||
/* Handle stabs continuation. */
|
/* Handle stabs continuation. */
|
||||||
{
|
{
|
||||||
char *stabstring = debug_info->ss + fh->issBase + sh.iss;
|
char *stabstring = debug_info->ss + fh->issBase + sh.iss;
|
||||||
|
/* If we need to heap-allocate STABSTRING, this owns
|
||||||
|
it. */
|
||||||
|
gdb::unique_xmalloc_ptr<char> stabstring_storage;
|
||||||
int len = strlen (stabstring);
|
int len = strlen (stabstring);
|
||||||
|
|
||||||
while (stabstring[len - 1] == '\\')
|
while (stabstring[len - 1] == '\\')
|
||||||
@ -2787,14 +2790,19 @@ parse_partial_symbols (minimal_symbol_reader &reader,
|
|||||||
stabstring2 = debug_info->ss + fh->issBase + sh2.iss;
|
stabstring2 = debug_info->ss + fh->issBase + sh2.iss;
|
||||||
len2 = strlen (stabstring2);
|
len2 = strlen (stabstring2);
|
||||||
|
|
||||||
/* Concatinate stabstring2 with stabstring1. */
|
/* Concatenate stabstring2 with stabstring1. */
|
||||||
if (stabstring
|
if (stabstring_storage != nullptr)
|
||||||
&& stabstring != debug_info->ss + fh->issBase + sh.iss)
|
{
|
||||||
stabstring
|
stabstring_storage.reset
|
||||||
= (char *) xrealloc (stabstring, len + len2 + 1);
|
((char *) xrealloc (stabstring_storage.release (),
|
||||||
|
len + len2 + 1));
|
||||||
|
stabstring = stabstring_storage.get ();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
stabstring = (char *) xmalloc (len + len2 + 1);
|
stabstring_storage.reset
|
||||||
|
((char *) xmalloc (len + len2 + 1));
|
||||||
|
stabstring = stabstring_storage.get ();
|
||||||
strcpy (stabstring, stabstring1);
|
strcpy (stabstring, stabstring1);
|
||||||
}
|
}
|
||||||
strcpy (stabstring + len, stabstring2);
|
strcpy (stabstring + len, stabstring2);
|
||||||
@ -3330,9 +3338,6 @@ parse_partial_symbols (minimal_symbol_reader &reader,
|
|||||||
hex_string (type_code)); /* CUR_SYMBOL_TYPE */
|
hex_string (type_code)); /* CUR_SYMBOL_TYPE */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (stabstring
|
|
||||||
&& stabstring != debug_info->ss + fh->issBase + sh.iss)
|
|
||||||
xfree (stabstring);
|
|
||||||
}
|
}
|
||||||
/* end - Handle continuation */
|
/* end - Handle continuation */
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user