Commit 9abe4231 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Fixed memory leak in parse().

parent 9d6d2747
Sat Sep 21 11:01:47 1991 Per Cederqvist (ceder at lysator)
* parser.c (parse): FREE (source_words) before returning.
Sat Jul 6 06:15:40 1991 Per Cederqvist (ceder at lysator) Sat Jul 6 06:15:40 1991 Per Cederqvist (ceder at lysator)
* Fixade makefilen s} att den kan generera b}de liblyskom-server.a * Fixade makefilen s} att den kan generera b}de liblyskom-server.a
......
/* /*
* $Id: parser.c,v 0.3 1991/09/15 10:22:45 linus Exp $ * $Id: parser.c,v 0.4 1991/09/21 12:04:23 ceder Exp $
* Copyright (C) 1991 Lysator Academic Computer Association. * Copyright (C) 1991 Lysator Academic Computer Association.
* *
* This file is part of the LysKOM server. * This file is part of the LysKOM server.
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
*/ */
static char *rcsid = "$Id: parser.c,v 0.3 1991/09/15 10:22:45 linus Exp $"; static char *rcsid = "$Id: parser.c,v 0.4 1991/09/21 12:04:23 ceder Exp $";
#include <stddef.h> #include <stddef.h>
...@@ -127,6 +127,9 @@ remove_parenthesis (String * str, ...@@ -127,6 +127,9 @@ remove_parenthesis (String * str,
* easier to parse than a string (since the string would have to * easier to parse than a string (since the string would have to
* be tokenized first anyway). The last entry is EMPTY_STRING. * be tokenized first anyway). The last entry is EMPTY_STRING.
* Returns NULL if any error occured (couldn't allocate memory). * Returns NULL if any error occured (couldn't allocate memory).
* The result from this function should be freed when it is no longer
* used by a FREE(Parse_token *). Note that String (Parse_token *)[X].word
* points into source, and should thus not be freed.
*/ */
EXPORT Parse_token * EXPORT Parse_token *
tokenize (const String source, tokenize (const String source,
...@@ -346,6 +349,7 @@ parse (String source_string, ...@@ -346,6 +349,7 @@ parse (String source_string,
/* Check if SOURCE_STRING was empty of words */ /* Check if SOURCE_STRING was empty of words */
if (no_of_source_words == 0) if (no_of_source_words == 0)
{ {
FREE (source_words);
answer.indexes = MALLOC (1 * sizeof(int)); answer.indexes = MALLOC (1 * sizeof(int));
if (answer.indexes == NULL) if (answer.indexes == NULL)
{ {
...@@ -407,6 +411,7 @@ parse (String source_string, ...@@ -407,6 +411,7 @@ parse (String source_string,
if (temp_indexes == NULL) if (temp_indexes == NULL)
{ {
/* Grumble! Out of memory. */ /* Grumble! Out of memory. */
FREE (source_words);
FREE (answer.indexes); FREE (answer.indexes);
answer.no_of_matches = -1; answer.no_of_matches = -1;
return answer; return answer;
...@@ -438,6 +443,7 @@ parse (String source_string, ...@@ -438,6 +443,7 @@ parse (String source_string,
if (answer.no_of_matches == 1) if (answer.no_of_matches == 1)
answer.arguments = s_strip_trailing (answer.arguments, separators); answer.arguments = s_strip_trailing (answer.arguments, separators);
FREE (source_words);
return answer; return answer;
} /* END: parse() */ } /* END: parse() */
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