From 41d1d28807deba7e7fe84b75945f2f65ce5b8e15 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 23 Oct 2002 00:29:25 +0000 Subject: [PATCH] Now handles readline() returning NULL correctly (user hits CTRL-D, etc). --- test/test_physfs.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/test_physfs.c b/test/test_physfs.c index 34078e41..ee67d059 100644 --- a/test/test_physfs.c +++ b/test/test_physfs.c @@ -714,10 +714,17 @@ static void trim_command(const char *orig, char *copy) static int process_command(char *complete_cmd) { const command_info *i; - char *cmd_copy = malloc(strlen(complete_cmd) + 1); + char *cmd_copy; char *args; int rc = 1; + if (complete_cmd == NULL) /* can happen if user hits CTRL-D, etc. */ + { + printf("\n"); + return(0); + } /* if */ + + cmd_copy = malloc(strlen(complete_cmd) + 1); if (cmd_copy == NULL) { printf("\n\n\nOUT OF MEMORY!\n\n\n"); @@ -877,7 +884,8 @@ int main(int argc, char **argv) #endif rc = process_command(buf); - free(buf); + if (buf != NULL) + free(buf); } while (rc); if (!PHYSFS_deinit())