From 5525a76b9cf6073181aafc842c1872ef41a2871b Mon Sep 17 00:00:00 2001 From: junsklee <50674368+junsklee@users.noreply.github.com> Date: Thu, 31 Oct 2024 13:00:36 +0900 Subject: [PATCH] memory leak check enhancements --- CTP/sql_by_cci/execute.c | 86 +++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/CTP/sql_by_cci/execute.c b/CTP/sql_by_cci/execute.c index 4fcea550..cd68886d 100644 --- a/CTP/sql_by_cci/execute.c +++ b/CTP/sql_by_cci/execute.c @@ -1184,55 +1184,67 @@ formatjoingraph (FILE * fp, char *joingraph) char *str, *p; int i, joingraphLen, newline; int joinflag = 0; + + if (joingraph == NULL) + { + return; + } + joingraphLen = strlen (joingraph); str = (char *) malloc (sizeof (char) * (joingraphLen + 1)); memset (str, 0, sizeof (char) * (joingraphLen + 1)); p = (char *) malloc (sizeof (char) * (joingraphLen + 1)); memset (p, 0, sizeof (char) * (joingraphLen + 1)); + + if (str == NULL || p == NULL) + { + free (str); + free (p); + return; + } + newline = 0; - - if (joingraph != NULL) + + for (i = 0; i < joingraphLen; i++) { - for (i = 0; i < joingraphLen; i++) + if (joingraph[i] == '\n') { - if (joingraph[i] == '\n') + strncpy (str, joingraph + newline, i - newline + 1); + strncpy (p, joingraph + newline, i - newline + 1); + str[i - newline + 1] = 0x00; + p[i - newline + 1] = 0x00; + newline = i + 1; + + trimline (p); + if (strlen (p) == 0) { - strncpy (str, joingraph + newline, i - newline + 1); - strncpy (p, joingraph + newline, i - newline + 1); - str[i - newline + 1] = 0x00; - p[i - newline + 1] = 0x00; - newline = i + 1; - - trimline (p); - if (strlen (p) == 0) - { - continue; - } - - if (startswith (p, "Join graph")) - { - joinflag = 1; - fprintf (fp, "%s", str); - continue; - } - else if (startswith (p, "Query plan:")) - { - joinflag = 0; - continue; - } - - if (joinflag == 1) - { - // hide selectivity by rewriting it as 'sel ?' - replace_substring (str, "sel [0-9]+\\.[0-9]+", "sel ?"); - fprintf (fp, "%s", str); - } + continue; + } + + if (startswith (p, "Join graph")) + { + joinflag = 1; + fprintf (fp, "%s", str); + continue; + } + else if (startswith (p, "Query plan:")) + { + joinflag = 0; + continue; + } + + if (joinflag == 1) + { + // hide selectivity by rewriting it as 'sel ?' + replace_substring (str, "sel [0-9]+\\.[0-9]+", "sel ?"); + fprintf (fp, "%s", str); } } - strncpy (str, joingraph + newline, i - newline + 1); - str[i - newline + 1] = 0x00; - fprintf (fp, "%s", str); } + strncpy (str, joingraph + newline, i - newline + 1); + str[i - newline + 1] = 0x00; + fprintf (fp, "%s", str); + free (str); free (p); }