mirror of
https://github.com/MariaDB/server.git
synced 2025-01-15 19:42:28 +01:00
Fixed memory leaks in resolve_stack_dump
- Remove memory leaks reported by safemalloc - Changed that all 0x strings are converted. This is needed to easily be able to resolve safemalloc backtraces
This commit is contained in:
parent
48eda61cd4
commit
749b988794
1 changed files with 30 additions and 15 deletions
|
@ -53,7 +53,7 @@ static struct my_option my_long_options[] =
|
|||
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
|
||||
{"version", 'V', "Output version information and exit.",
|
||||
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
|
||||
{"symbols-file", 's', "Use specified symbols file.", &sym_fname,
|
||||
{"symbols-file", 's', "Use specified symbols file", &sym_fname,
|
||||
&sym_fname, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
||||
{"numeric-dump-file", 'n', "Read the dump from specified file.",
|
||||
&dump_fname, &dump_fname, 0, GET_STR, REQUIRED_ARG,
|
||||
|
@ -63,7 +63,7 @@ static struct my_option my_long_options[] =
|
|||
|
||||
|
||||
static void verify_sort();
|
||||
|
||||
static void clean_up();
|
||||
|
||||
static void print_version(void)
|
||||
{
|
||||
|
@ -97,9 +97,18 @@ static void die(const char* fmt, ...)
|
|||
vfprintf(stderr, fmt, args);
|
||||
fprintf(stderr, "\n");
|
||||
va_end(args);
|
||||
clean_up();
|
||||
my_end(0);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void local_exit(int error)
|
||||
{
|
||||
clean_up();
|
||||
my_end(0);
|
||||
exit(error);
|
||||
}
|
||||
|
||||
|
||||
static my_bool
|
||||
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
|
||||
|
@ -108,10 +117,12 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
|
|||
switch(optid) {
|
||||
case 'V':
|
||||
print_version();
|
||||
exit(0);
|
||||
local_exit(0);
|
||||
break;
|
||||
case '?':
|
||||
usage();
|
||||
exit(0);
|
||||
local_exit(0);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -122,7 +133,7 @@ static int parse_args(int argc, char **argv)
|
|||
int ho_error;
|
||||
|
||||
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
|
||||
exit(ho_error);
|
||||
local_exit(ho_error);
|
||||
|
||||
/*
|
||||
The following code is to make the command compatible with the old
|
||||
|
@ -143,13 +154,13 @@ static int parse_args(int argc, char **argv)
|
|||
else
|
||||
{
|
||||
usage();
|
||||
exit(1);
|
||||
local_exit(1);
|
||||
}
|
||||
}
|
||||
else if (argc != 0 || !sym_fname)
|
||||
{
|
||||
usage();
|
||||
exit(1);
|
||||
local_exit(1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -242,6 +253,10 @@ static void init_sym_table()
|
|||
static void clean_up()
|
||||
{
|
||||
delete_dynamic(&sym_table);
|
||||
if (fp_dump && fp_dump != stdin)
|
||||
my_fclose(fp_dump, MYF(0));
|
||||
if (fp_sym)
|
||||
my_fclose(fp_sym, MYF(0));
|
||||
}
|
||||
|
||||
static void verify_sort()
|
||||
|
@ -283,7 +298,7 @@ static SYM_ENTRY* resolve_addr(uchar* addr, SYM_ENTRY* se)
|
|||
|
||||
|
||||
/*
|
||||
Resolve anything that starts with [0x or (+0x or start of line and 0x
|
||||
Resolve anything that starts with [0x or (+0x or 0x
|
||||
Skip '_end' as this is an indication of a wrong symbol (stack?)
|
||||
*/
|
||||
|
||||
|
@ -299,9 +314,7 @@ static void do_resolve()
|
|||
found= 3;
|
||||
if (p[0] == '(' && p[1] == '+' && p[2] == '0' && p[3] == 'x')
|
||||
found= 4;
|
||||
|
||||
/* For stdin */
|
||||
if (p == buf && p[0] == '0' && p[1] == 'x')
|
||||
if (p[0] == '0' && p[1] == 'x')
|
||||
found= 2;
|
||||
|
||||
if (found)
|
||||
|
@ -312,14 +325,15 @@ static void do_resolve()
|
|||
addr= (uchar*)read_addr(&tmp);
|
||||
if (resolve_addr(addr, &se) && strcmp(se.symbol, "_end"))
|
||||
{
|
||||
fprintf(fp_out, "%c%p %s + %d", *p, addr, se.symbol,
|
||||
(int) (addr - se.addr));
|
||||
found-= 2; /* Don't print 0x as it's added by %p */
|
||||
while (found--)
|
||||
fputc(*p++, stdout);
|
||||
fprintf(fp_out, "%p %s + %d", addr,
|
||||
se.symbol, (int) (addr - se.addr));
|
||||
p= tmp-1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fputc(*p, stdout);
|
||||
}
|
||||
}
|
||||
else
|
||||
fputc(*p, stdout);
|
||||
|
@ -336,5 +350,6 @@ int main(int argc, char** argv)
|
|||
init_sym_table();
|
||||
do_resolve();
|
||||
clean_up();
|
||||
my_end(0);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue