0

When I comment the indicated line, I don't have any problem. But when I dont I get the "free(): invalid next size (normal)" error. Any help would be appreciated.

Here's the code- Main.c:

MYSQL_RES *result = run_query("SELECT * FROM Zones");
int num_fields = mysql_num_fields(result);

while ((row = mysql_fetch_row(result))) 
{ 
    for(i = 0; i < num_fields; i++) 
  { 
      printf("%s ", row[i] ? row[i] : "NULL"); 
  } 
      printf("\n"); 
}
mysql_free_result(result);             /*Problem is with this line*/

And here's the run_query() function:

MYSQL_RES* run_query(char query[200]) {

    if (mysql_query(con, query)) 
    {
        finish_with_error(con);
    }

    MYSQL_RES *result = mysql_store_result(con);

    if (result == NULL) 
    {
        finish_with_error(con);
    }
    else{
        return result;
    }
    return NULL;
}
Zaxter
  • 2,939
  • 3
  • 31
  • 48
  • Maybe you should check for NULL. – Fred Larson Oct 02 '14 at 13:45
  • 1
    Compile with all warnings and debug info (`gcc -Wall -g`). Use the debugger (`gdb`) and [valgrind](http://valgrind.org/). You don't need your `run_query` (you should call directly [mysql_real_query](http://dev.mysql.com/doc/refman/5.7/en/mysql-real-query.html)). I guess you could have a memory leak *elsewhere*. – Basile Starynkevitch Oct 02 '14 at 14:04
  • I used valgrind and the program doesn't crash. No errors reported. – Zaxter Oct 02 '14 at 14:07
  • 1
    This [question](http://stackoverflow.com/q/2317021/841108) could be related. – Basile Starynkevitch Oct 02 '14 at 14:39
  • Possible duplicate of [Error: free(): invalid next size (fast):](https://stackoverflow.com/questions/4729395/error-free-invalid-next-size-fast) – Raedwald Nov 22 '18 at 09:02

0 Answers0