]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Fix a bug in sqlite table loader.
authorChris Porter <redacted>
Thu, 2 Oct 2008 02:55:04 +0000 (03:55 +0100)
committerChris Porter <redacted>
Thu, 2 Oct 2008 02:55:04 +0000 (03:55 +0100)
sqlite/sqlite.c
sqlite/sqlite.h

index 7ff234d8c9cb7f44d63316accf10527b044b7ddd..746f7848aea4b8d5a7cdf920ed3756487f5bb21e 100644 (file)
@@ -45,6 +45,8 @@ static int inited;
 
 #define SYNC_MODE "OFF"
 
+#define FLAG_DONTFREE 0x02
+
 static void sqlitequeueprocessor(void *arg);
 static void dbstatus(int hooknum, void *arg);
 
@@ -133,6 +135,7 @@ static void processstatement(int rc, sqlite3_stmt *s, SQLiteQueryHandler handler
 
     r = (SQLiteResult *)nsmalloc(POOL_SQLITE, sizeof(SQLiteResult));
     r->r = s;
+    r->flags = 0;
     r->first = 1;
     if(rc == SQLITE_ROW) {
       r->final = 0;
@@ -292,6 +295,9 @@ void sqliteclear(SQLiteResult *r) {
   if(!r)
     return;
 
+  if(r->flags & FLAG_DONTFREE)
+    return;
+
   if(r->r)
     sqlite3_finalize(r->r);
 
@@ -313,18 +319,26 @@ struct sqlitetableloader {
 
 static void loadtablerows(SQLiteConn *c, void *tag) {
   struct sqlitetableloader *t = (struct sqlitetableloader *)tag;
+  SQLiteResult *r = (SQLiteResult *)c;
 
   if(!c) { /* pqsql doesnt call the handlers so we don't either */
     nsfree(POOL_SQLITE, t);
     return;
   }
 
+  r->flags|=FLAG_DONTFREE;
+
   /* the handlers do all the checking and cleanup */
   if(t->init)
     (t->init)(c, t->tag);
 
+  if(!t->fini)
+    r->flags&=~FLAG_DONTFREE;
+
   (t->data)(c, t->tag);
 
+  r->flags&=~FLAG_DONTFREE;
+
   if(t->fini)
     (t->fini)(c, t->tag);
 
index d506d0cd938ab1e6bdf879abfcaa22f3f025ed7a..e5cf11460bc5193588d4bb55a3cbee509f39044e 100644 (file)
@@ -8,6 +8,7 @@
 typedef struct SQLiteResult {
   sqlite3_stmt *r;
   char first, final;
+  short flags;
 } SQLiteResult;
 
 typedef SQLiteResult SQLiteConn;