mysql_real_escape_string memory leak ?
In this example:
Code:
char *_sql(const char *dataIn)
{
char *to = new char[(strlen(dataIn) * 2) + 1];
mysql_real_escape_string(MySQL_Database_Connection__global, to, dataIn, strlen(dataIn));
dataIn = '\0';
return (to);
}
char szQueryText[MAX_SQL_LENGTH] = "";
char *text = "Hello World";
snprintf(szQueryText, sizeof(szQueryText), "UPDATE this_table SET this_field = '%s' WHERE this_value = 1 ;", _sql(text));
My_result = MySQL__query(szQueryText);
MySQL__endquery(My_result);
Everything works great. Data is perfect. No errors, no issues. However... when I pull up windows task manager and look at how much memory the program that's running this code is using, every time this code is invoked, the memory goes up. Obviously, there's a memory leak somewhere. I'm not free'ing something right?
If I change: to No memory going up at all, hence, in my opinion, no leak. So...
Where in my char *_sql(const char *dataIn) function am I going wrong?
Thanks.