[gcalctool] Fix memory leak and failure to quit in gcalccmd
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcalctool] Fix memory leak and failure to quit in gcalccmd
- Date: Tue, 6 Apr 2010 04:49:26 +0000 (UTC)
commit d58f374207c2cd259b63a151402d1899555e3175
Author: Robert Ancell <robert ancell gmail com>
Date: Tue Apr 6 14:46:57 2010 +1000
Fix memory leak and failure to quit in gcalccmd
src/gcalccmd.c | 23 +++++++++++------------
1 files changed, 11 insertions(+), 12 deletions(-)
---
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]