While i can't answer the question about the leaks, i can say...
On Tue, Sep 6, 2011 at 10:49 AM, Grice, Lynton (L)
<[email protected]>wrote:
> int queue_peekByTID(const char *tid, message *msg){
> What is wrong with my code above? Must I FREE the char*? Why would
> something say it was a "leak"?
>
This technically isn't legal any more:
char *eventLogTable = "CREATE TABLE IF NOT EXISTS [log] ( "...
that should be const char *.
And NEVER free() a stack-allocated string.
I am also getting it complaining when I do a "sqlite3_finalize(stmt);"
>
If that's happening then it is likely that either your db is hosed,
sqlite3_prepare() failed, or you're finalize()ing twice. Your code above
does not check the return value of prepare(), and there ARE reasons a
prepare() can fail which have nothing to do with the validity of the SQL you
give it.
> p = sqlite3_malloc(256);
> sqlite3_busy_handler(handle, &eventLoggerBusyHandler, p);
> sqlite3_free(p);
>
That almost certainly is not what you want to do. p will be passed to the
busy handler, but it will be invalid because you free()d it. That same
address might later be re-allocated to a different type of object, which
would then (invalidly) be accessed by the busy handler. i.e. memory
corruption (which might even be a source of reported leaks).
sqlite3_exec(handle,"PRAGMA default_cache_size = 50;",0,0,0);
>
are you sure this cannot fail?
rc = sqlite3_exec(handle,journalMode,0,0,0);
> if(rc == OK){
> rc = sqlite3_exec(handle,eventLogTable,0,0,0);
> if(rc == OK){
> rc = sqlite3_exec(handle,trigger,0,0,0);
> }
> }
> }
> return successFlag;
>
wouldn't it be simpler (and more accurate) to return rc instead of
successFlag (which is not set properly, IMO, if journalMode, eventLogTable,
or trigger fail to exec().
--
----- stephan beal
http://wanderinghorse.net/home/stephan/
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users