Commit 842f4e65 authored by Robert Sprowson's avatar Robert Sprowson
Browse files

Fix for memory leak in error case

Rather than leak 40 bytes by failing to free(), just use an automatic variable and let the compiler worry about function exits.
From a tip off in https://www.riscosopen.org/forum/forums/4/topics/3990

Version 0.42. Tagged as 'Gadgets-0_42'
parent 56b1cd40
/* (0.41)
/* (0.42)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 0.41
#define Module_MajorVersion_CMHG 0.42
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 25 Mar 2016
#define Module_Date_CMHG 02 May 2016
#define Module_MajorVersion "0.41"
#define Module_Version 41
#define Module_MajorVersion "0.42"
#define Module_Version 42
#define Module_MinorVersion ""
#define Module_Date "25 Mar 2016"
#define Module_Date "02 May 2016"
#define Module_ApplicationDate "25-Mar-16"
#define Module_ApplicationDate "02-May-16"
#define Module_ComponentName "Gadgets"
#define Module_ComponentPath "castle/RiscOS/Sources/Toolbox/Gadgets"
#define Module_FullVersion "0.41"
#define Module_HelpVersion "0.41 (25 Mar 2016)"
#define Module_LibraryVersionInfo "0:41"
#define Module_FullVersion "0.42"
#define Module_HelpVersion "0.42 (02 May 2016)"
#define Module_LibraryVersionInfo "0:42"
......@@ -783,6 +783,7 @@ _kernel_oserror *insert_text(Text *text, char *s,
int last_line = first_line;
char *old_end;
Scan scan;
int new_lines[10];
int old_split = 0;
int old_line_no;
......@@ -793,16 +794,8 @@ _kernel_oserror *insert_text(Text *text, char *s,
return make_error(TextGadgets_IntMallocFail, 0);
}
scan.new_lines = malloc(10 * sizeof(int));
/* If the malloc fails */
if (scan.new_lines == NULL)
{
/* return an error message */
return make_error(TextGadgets_IntMallocFail, 0);
}
scan.max_line = 9;
scan.new_lines = new_lines;
scan.max_line = (sizeof(new_lines) / sizeof(new_lines[0])) - 1;
scan.line_no = 0;
if(left <= str_size)
......@@ -907,7 +900,6 @@ _kernel_oserror *insert_text(Text *text, char *s,
for(i = 0; i < scan.line_no; i++)
text->line_table[first_line + i] = scan.new_lines[i];
free(scan.new_lines);
*first_line_p = first_line;
text->insert_line += ld;
......
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