From 13d9e3cb19836cfdb70c1124ae86c7a78cf831ab Mon Sep 17 00:00:00 2001 From: oetiker Date: Thu, 22 Oct 2009 23:22:23 +0000 Subject: [PATCH] fix memory handling when argument separation in pipe mode fails. fix for #230 git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk@1944 a5681a0c-68f1-0310-ab6d-d61299d08faa --- program/src/rrd_tool.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/program/src/rrd_tool.c b/program/src/rrd_tool.c index bda631d2..7464b3cd 100644 --- a/program/src/rrd_tool.c +++ b/program/src/rrd_tool.c @@ -29,7 +29,6 @@ int CountArgs( int CreateArgs( char *, char *, - int, char **); int HandleInputLine( int, @@ -468,24 +467,21 @@ int main( } while (fgetslong(&aLine, stdin)) { + char *aLineOrig = aLine; if ((argc = CountArgs(aLine)) == 0) { free(aLine); printf("ERROR: not enough arguments\n"); + continue; } if ((myargv = (char **) malloc((argc + 1) * sizeof(char *))) == NULL) { perror("malloc"); exit(1); } - if ((argc = CreateArgs(argv[0], aLine, argc, myargv)) < 0) { - free(aLine); - free(myargv); + if ((argc = CreateArgs(argv[0], aLine, myargv)) < 0) { printf("ERROR: creating arguments\n"); } else { - int ret = HandleInputLine(argc, myargv, stdout); - - free(myargv); - if (ret == 0) { + if ( HandleInputLine(argc, myargv, stdout) == 0 ){ #if HAVE_GETRUSAGE getrusage(RUSAGE_SELF, &myusage); gettimeofday(¤ttime, NULL); @@ -504,7 +500,8 @@ int main( } } fflush(stdout); /* this is important for pipes to work */ - free(aLine); + free(myargv); + free(aLineOrig); } } else if (argc == 2) { PrintUsage(argv[1]); @@ -857,7 +854,6 @@ int CountArgs( int CreateArgs( char *pName, char *aLine, - int argc, char **argv) { char *getP, *putP; @@ -865,6 +861,7 @@ int CreateArgs( char Quote = 0; int inArg = 0; int len; + int argc = 1; len = strlen(aLine); /* remove trailing space and newlines */ -- 2.30.2