Commit a6adbd05 authored by Nirbhay Choubey's avatar Nirbhay Choubey

Bug#14685362 : MEMORY LEAKS IN MYSQL CLIENT IN

  INTERACTIVE MODE

In interactive mode, libedit/readline allocates memory
for every new line entered & later the allocated memory
never gets freed.

Fixed by freeing the allocated memory blocks appropriately.
parent cc5876d2
/* /*
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -1869,7 +1869,7 @@ static int read_and_execute(bool interactive) ...@@ -1869,7 +1869,7 @@ static int read_and_execute(bool interactive)
String buffer; String buffer;
#endif #endif
char *line; char *line= NULL;
char in_string=0; char in_string=0;
ulong line_number=0; ulong line_number=0;
bool ml_comment= 0; bool ml_comment= 0;
...@@ -1944,6 +1944,13 @@ static int read_and_execute(bool interactive) ...@@ -1944,6 +1944,13 @@ static int read_and_execute(bool interactive)
#else #else
if (opt_outfile) if (opt_outfile)
fputs(prompt, OUTFILE); fputs(prompt, OUTFILE);
/*
free the previous entered line.
Note: my_free() cannot be used here as the memory was allocated under
the readline/libedit library.
*/
if (line)
free(line);
line= readline(prompt); line= readline(prompt);
#endif /* defined(__WIN__) || defined(__NETWARE__) */ #endif /* defined(__WIN__) || defined(__NETWARE__) */
...@@ -2003,8 +2010,17 @@ static int read_and_execute(bool interactive) ...@@ -2003,8 +2010,17 @@ static int read_and_execute(bool interactive)
#endif #endif
#if defined(__WIN__) #if defined(__WIN__)
tmpbuf.free(); tmpbuf.free();
#else
if (interactive)
/*
free the last entered line.
Note: my_free() cannot be used here as the memory was allocated under
the readline/libedit library.
*/
free(line);
#endif #endif
return status.exit_status; return status.exit_status;
} }
......
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