]> git.webhop.me Git - lcd4linux.git/commitdiff
[lcd4linux @ 2004-02-26 21:42:45 by reinelt]
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Thu, 26 Feb 2004 21:42:45 +0000 (21:42 +0000)
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Thu, 26 Feb 2004 21:42:45 +0000 (21:42 +0000)
memory leak fixes from Martin

git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@377 3ae390bd-cb1e-0410-b409-cd5a39f66f1f

evaluator.c

index 9d497e721f2f984f0ddf296d094a8958ca190991..17fee4ce705d6bcab98487bc4b3da1c8f84389e5 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: evaluator.c,v 1.12 2004/02/05 07:10:23 reinelt Exp $
+/* $Id: evaluator.c,v 1.13 2004/02/26 21:42:45 reinelt Exp $
  *
  * expression evaluation
  *
@@ -10,6 +10,9 @@
  * FIXME: GPL or not GPL????
  *
  * $Log: evaluator.c,v $
+ * Revision 1.13  2004/02/26 21:42:45  reinelt
+ * memory leak fixes from Martin
+ *
  * Revision 1.12  2004/02/05 07:10:23  reinelt
  * evaluator function names are no longer case-sensitive
  * Crystalfontz Fan PWM control, Fan RPM monitoring, temperature monitoring
@@ -316,6 +319,7 @@ char* R2S (RESULT *result)
   if (result->type & R_NUMBER) {
     sprintf(buffer, "%g", result->number);
     result->type |= R_STRING;
+    if (result->string) free(result->string);
     result->string=strdup(buffer);
     return result->string;
   }
@@ -370,8 +374,13 @@ static int GetVariable (char *name, RESULT *value)
   if (V!=NULL) {
     value->type=V->value->type;
     value->number=V->value->number;
-    if (V->value->string!=NULL) value->string=strdup(V->value->string);
-    else value->string=NULL;
+    if(value->string) {
+      free(value->string);
+      value->string=0;
+    }
+    if (V->value->string!=NULL) {
+      value->string=strdup(V->value->string);
+    }
     return 1;
   }