This patch fixes memory allocation problems with column names in both 1.2.2 and trunk. It compiled fine on FC4.

--
Bojan
diff -rauN apr-util-1.2.2-vanilla/dbd/apr_dbd_sqlite3.c apr-util-1.2.2/dbd/apr_dbd_sqlite3.c
--- apr-util-1.2.2-vanilla/dbd/apr_dbd_sqlite3.c	2005-08-11 18:51:16.000000000 +1000
+++ apr-util-1.2.2/dbd/apr_dbd_sqlite3.c	2006-02-24 11:16:06.000000000 +1100
@@ -65,6 +65,7 @@
     apr_dbd_row_t *next_row;
     size_t sz;
     int tuples;
+    char **col_names;
 };
 
 struct apr_dbd_prepared_t {
@@ -109,6 +110,8 @@
         (*results)->random = seek;
         (*results)->next_row = 0;
         (*results)->tuples = 0;
+        (*results)->col_names = apr_pcalloc(pool,
+                                            column_count * sizeof(char *));
         do {
             ret = sqlite3_step((*results)->stmt);
             if (ret == SQLITE_BUSY) {
@@ -131,7 +134,13 @@
                 for (i = 0; i < (*results)->sz; i++) {
                     column = apr_palloc(pool, sizeof(apr_dbd_column_t));
                     row->columns[i] = column;
-                    column->name = (char *) sqlite3_column_name((*results)->stmt, i);
+                    /* copy column name once only */
+                    if ((*results)->col_names[i] == NULL) {
+                      (*results)->col_names[i] =
+                          apr_pstrdup(pool,
+                                      sqlite3_column_name((*results)->stmt, i));
+                    }
+                    column->name = (*results)->col_names[i];
                     column->size = sqlite3_column_bytes((*results)->stmt, i);
                     column->type = sqlite3_column_type((*results)->stmt, i);
                     switch (column->type) {

Reply via email to