You can call the mysql_stmt_free_result() function to free the memory associated with the result set produced by the execution of a prepared statement.
Syntax
my_bool
mysql_stmt_free_result(MYSQL_STMT *stmt)
Return values
0 is returned for an execution success, and a non-zero value is returned if an error occurred.
Notes
If a cursor is open for the statement, mysql_stmt_free_result() closes it.