From 46a52f381cb45353b9ae66bf06d2145c9d875f4a Mon Sep 17 00:00:00 2001 From: schnetter Date: Wed, 27 Feb 2008 05:20:47 +0000 Subject: Correct malloc error and memory leak when the tag "whiskycartoon" is used git-svn-id: http://svn.cactuscode.org/arrangements/CactusNumerical/Cartoon2D/trunk@103 eec4d7dc-71c2-46d6-addf-10296150bf52 --- src/ApplyCartoon.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/ApplyCartoon.c b/src/ApplyCartoon.c index f0e48ed..89cfd1d 100644 --- a/src/ApplyCartoon.c +++ b/src/ApplyCartoon.c @@ -94,7 +94,7 @@ void Cartoon_ApplyBoundaries(CCTK_ARGUMENTS) char prolongtype[PROLONG_BUFF_SIZE]; int prolongmethod; - int tableindex, len; + int whiskycartoon, len; @@ -160,13 +160,30 @@ void Cartoon_ApplyBoundaries(CCTK_ARGUMENTS) len = Util_TableGetString(group_tags_table,0,NULL,"whiskycartoon"); - char* value = malloc (len + 1); - Util_TableGetString (group_tags_table, len + 1, value, "whiskycartoon"); - + whiskycartoon = 1; /* default is yes */ + if (len >= 0) + { + char* value = malloc (len + 1); + Util_TableGetString (group_tags_table, len + 1, value, "whiskycartoon"); + if (CCTK_Equals(value, "yes")) + { + whiskycartoon = 1; + } + else if (CCTK_Equals(value, "no")) + { + whiskycartoon = 0; + } + else + { + CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Tags table entry \"whiskycartoon\" for variable group %s should be either \"yes\" or \"no\", but is \"%s\"", + CCTK_GroupName(gi), value); + } + free (value); + } - if (len <= 0 || CCTK_Equals(value, "yes")) + if (whiskycartoon) { - free(value); /*###################################################################*/ -- cgit v1.2.3