Hi all,

Firstly, forgive me for a slightly naïve question; I don’t normally code in
C and I’m having problems freeing up memory.

Basically I have a structure I use to hold data results:

//=====================
typedef struct {
  char   *sqlStatement; // Either the sqlstatement to be executed or the
last statement that was executed
  char   **results;     // the result stored in an array
  char   *err_msg;      // the error message
  int    numrows;       // number of rows of results
  int    numcols;       // the number of columns of data returned
} RESULT_T;
//=======================

I pass this structure to a wrapper function that ultimately calls
sqlite3_get_table and returns the results structure on tresults

//=======================
int execute_command (size_t   nbytes,  char     *command,   RESULT_T
*tresults)
//=======================

In the function that calls execute_command(), I want to free up the memory
that was allocated by sqlite3_get_table().

Do I just call the free function like this:
sqlite3_free_table(tresults.results); (assuming that I created a variable
called ‘tresults’ of type RESULT_T in the calling function).

I’ve tried quite a few permutations and am never quite sure if I’ve actually
freed up the memory. Is there a fool proof way to check?

Also, how do I free up the error messages? What if there are no results
returned by sqlite3_get_table, can I still attempt to free up the memory
with ‘sqlite3_free_table’

I appreciate you reading down this far, and sorry if my code snips are hard
to follow!!

TIA
Richard.

Reply via email to