projects
/
open-adventure.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Stop leaking memory
[open-adventure.git]
/
main.c
diff --git
a/main.c
b/main.c
index 4a92f00835d3f4c616b50fe95ae1b4d7f6c7b670..61a2267a59b183f6879f132c9001493938888111 100644
(file)
--- a/
main.c
+++ b/
main.c
@@
-13,7
+13,7
@@
* and for the offensive globals. Applying the Structured Program
* Theorem can be hard.
*/
* and for the offensive globals. Applying the Structured Program
* Theorem can be hard.
*/
-#define DEFINE_GLOBALS_FROM_INCLUDES
+
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
@@
-29,9
+29,6
@@
struct game_t game;
struct game_t game;
-long LNLENG, LNPOSN;
-char rawbuf[LINESIZE], INLINE[LINESIZE + 1];
-
FILE *logfp = NULL, *rfp = NULL;
bool oldstyle = false;
bool editline = true;
FILE *logfp = NULL, *rfp = NULL;
bool oldstyle = false;
bool editline = true;
@@
-45,7
+42,7
@@
static void sig_handler(int signo)
if (logfp != NULL)
fflush(logfp);
}
if (logfp != NULL)
fflush(logfp);
}
- exit(
0
);
+ exit(
EXIT_FAILURE
);
}
// LCOV_EXCL_STOP
}
// LCOV_EXCL_STOP
@@
-116,7
+113,7
@@
int main(int argc, char *argv[])
#endif
fprintf(stderr,
" -s suppress command editing\n");
#endif
fprintf(stderr,
" -s suppress command editing\n");
- exit(
-1
);
+ exit(
EXIT_FAILURE
);
break;
}
}
break;
}
}
@@
-1032,6
+1029,8
@@
L2600:
/* This is where we get a new command from the user */
char* input;
/* This is where we get a new command from the user */
char* input;
+ char inputbuf[LINESIZE];
+
for (;;) {
input = get_input();
if (input == NULL)
for (;;) {
input = get_input();
if (input == NULL)
@@
-1043,8
+1042,12
@@
L2600:
if (strcmp(input, "") != 0)
break;
}
if (strcmp(input, "") != 0)
break;
}
+
+ strncpy(inputbuf, input, LINESIZE - 1);
+ linenoiseFree(input);
+
long tokens[4];
long tokens[4];
- tokenize(input, tokens);
+ tokenize(input
buf
, tokens);
command.wd1 = tokens[0];
command.wd1x = tokens[1];
command.wd2 = tokens[2];
command.wd1 = tokens[0];
command.wd1x = tokens[1];
command.wd2 = tokens[2];
@@
-1121,7
+1124,7
@@
Lookup:
defn = get_vocab_id(word1);
if (defn == -1) {
/* Gee, I don't understand. */
defn = get_vocab_id(word1);
if (defn == -1) {
/* Gee, I don't understand. */
- if (fallback_handler(input))
+ if (fallback_handler(input
buf
))
continue;
rspeak(DONT_KNOW, command.wd1, command.wd1x);
goto L2600;
continue;
rspeak(DONT_KNOW, command.wd1, command.wd1x);
goto L2600;
@@
-1184,7
+1187,6
@@
Laction:
default:
BUG(ACTION_RETURNED_PHASE_CODE_BEYOND_END_OF_SWITCH); // LCOV_EXCL_LINE
}
default:
BUG(ACTION_RETURNED_PHASE_CODE_BEYOND_END_OF_SWITCH); // LCOV_EXCL_LINE
}
- linenoiseFree(input);
}
}
}
}