Commit 442afcf4 authored by unknown's avatar unknown

Fixed memory leak in mysql_upgrade


client/mysql_upgrade.c:
  Fixed memory leak
  Fixed indentation
parent 3a520a78
...@@ -171,7 +171,7 @@ void set_extra_default(int id, const struct my_option *opt) ...@@ -171,7 +171,7 @@ void set_extra_default(int id, const struct my_option *opt)
} }
d= (extra_default_t *)my_malloc(sizeof(extra_default_t), d= (extra_default_t *)my_malloc(sizeof(extra_default_t),
MYF(MY_FAE|MY_ZEROFILL)); MYF(MY_FAE | MY_ZEROFILL));
d->id= id; d->id= id;
d->name= opt->name; d->name= opt->name;
d->n_len= strlen(opt->name); d->n_len= strlen(opt->name);
...@@ -345,15 +345,17 @@ static int create_defaults_file(const char *path, const char *forced_path) ...@@ -345,15 +345,17 @@ static int create_defaults_file(const char *path, const char *forced_path)
} }
dynstr_set(&buf, NULL); dynstr_set(&buf, NULL);
} }
if (dynstr_append_mem(&buf, "\n", 1) if (dynstr_append_mem(&buf, "\n", 1) ||
|| dynstr_append_mem(&buf, d->name, d->n_len) dynstr_append_mem(&buf, d->name, d->n_len) ||
|| (d->v_len && (dynstr_append_mem(&buf, "=", 1) (d->v_len && (dynstr_append_mem(&buf, "=", 1) ||
|| dynstr_append_mem(&buf, d->value, d->v_len)))) dynstr_append_mem(&buf, d->value, d->v_len))))
{ {
ret= 1; ret= 1;
goto error; goto error;
} }
my_delete((gptr)d, MYF(0)); my_delete((gptr)d, MYF(0));
my_free((gptr) d, MYF(0));
list_pop(extra_defaults); /* pop off the head */ list_pop(extra_defaults); /* pop off the head */
} }
if (my_write(defaults_file, buf.str, buf.length, MYF(MY_FNABP | MY_WME))) if (my_write(defaults_file, buf.str, buf.length, MYF(MY_FNABP | MY_WME)))
...@@ -451,10 +453,10 @@ int main(int argc, char **argv) ...@@ -451,10 +453,10 @@ int main(int argc, char **argv)
char *forced_extra_defaults; char *forced_extra_defaults;
char *local_defaults_group_suffix; char *local_defaults_group_suffix;
const char *script_line; const char *script_line;
char *upgrade_defaults_path; char *upgrade_defaults_path= NULL;
char *defaults_to_use= NULL; char *defaults_to_use= NULL;
int upgrade_defaults_created= 0; int upgrade_defaults_created= 0;
int no_defaults;
char path[FN_REFLEN]; char path[FN_REFLEN];
DYNAMIC_STRING cmdline; DYNAMIC_STRING cmdline;
...@@ -464,6 +466,10 @@ int main(int argc, char **argv) ...@@ -464,6 +466,10 @@ int main(int argc, char **argv)
#endif #endif
/* Check if we are forced to use specific defaults */ /* Check if we are forced to use specific defaults */
no_defaults= 0;
if (argc >= 2 && !strcmp(argv[1],"--no-defaults"))
no_defaults= 1;
get_defaults_options(argc, argv, get_defaults_options(argc, argv,
&forced_defaults_file, &forced_extra_defaults, &forced_defaults_file, &forced_extra_defaults,
&local_defaults_group_suffix); &local_defaults_group_suffix);
...@@ -652,7 +658,9 @@ int main(int argc, char **argv) ...@@ -652,7 +658,9 @@ int main(int argc, char **argv)
if (defaults_to_use) if (defaults_to_use)
{ {
dynstr_append(&cmdline, " "); dynstr_append(&cmdline, " ");
dynstr_append_os_quoted(&cmdline, "--defaults-extra-file=", dynstr_append_os_quoted(&cmdline,
(no_defaults ? "--defaults-file=" :
"--defaults-extra-file="),
defaults_to_use, NullS); defaults_to_use, NullS);
} }
dynstr_append(&cmdline, " "); dynstr_append(&cmdline, " ");
...@@ -684,6 +692,7 @@ int main(int argc, char **argv) ...@@ -684,6 +692,7 @@ int main(int argc, char **argv)
if (upgrade_defaults_created) if (upgrade_defaults_created)
my_delete(upgrade_defaults_path, MYF(0)); my_delete(upgrade_defaults_path, MYF(0));
my_free(upgrade_defaults_path, MYF(MY_ALLOW_ZERO_PTR));
my_end(info_flag ? MY_CHECK_ERROR | MY_GIVE_INFO : 0); my_end(info_flag ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment