[gcalctool/gnome-2-30] Fix memory leak in gcalccmd and failure to quit on EOF (Bug #614875)



commit 0a797a35c15ed3b7fe600b97459443224861838c
Author: Robert Ancell <robert ancell gmail com>
Date:   Tue Apr 6 14:48:12 2010 +1000

    Fix memory leak in gcalccmd and failure to quit on EOF (Bug #614875)

 NEWS           |    2 ++
 src/gcalccmd.c |   23 +++++++++++------------
 2 files changed, 13 insertions(+), 12 deletions(-)
---
diff --git a/NEWS b/NEWS
index c59a5fe..55e8cf8 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,8 @@ Overview of changes in gcalctool 5.30.1
     * Fix bug stopping translations from working (Gert Kulyk, Bug #614489)
     
     * Mark strings for translation that were missing (Gert Kulyk, Bug #614491)
+    
+    * Fix memory leak in gcalccmd and failure to quit on EOF (Bug #614875)
  
 Overview of changes in gcalctool 5.30.0
 
diff --git a/src/gcalccmd.c b/src/gcalccmd.c
index d2d5d8b..64f3330 100644
--- a/src/gcalccmd.c
+++ b/src/gcalccmd.c
@@ -79,21 +79,20 @@ main(int argc, char **argv)
     /* Seed random number generator. */
     srand48((long) time((time_t *) 0));
 
+    equation = (char *) malloc(MAXLINE * sizeof(char));
     while (1) {
         printf("> ");
-        equation = (char *) malloc(MAXLINE * sizeof(char));
         bytes_read = getline(&equation, &nbytes, stdin);
-
-        if (bytes_read != -1) {
+      
+        if (bytes_read >= 0)
             str_adjust(equation);
-            if (!strcmp(equation, "exit") || !strcmp(equation, "quit") ||
-                strlen(equation) == 0) {
-                printf("\n");
-                exit(1);
-            } else {
-                solve(equation);
-                free(equation);
-            }
-        }
+
+        if (bytes_read < 0 || strcmp(equation, "exit") == 0 || strcmp(equation, "quit") == 0 || strlen(equation) == 0)
+            break;
+
+        solve(equation);
     }
+    free(equation);
+
+    return 0;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]