Skip to content

Commit

Permalink
memory leak check enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
junsklee committed Oct 31, 2024
1 parent dbe5f8a commit 5525a76
Showing 1 changed file with 49 additions and 37 deletions.
86 changes: 49 additions & 37 deletions CTP/sql_by_cci/execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 5525a76

Please sign in to comment.