[plt-scheme] sqlite.plt seg faults with 370

From: Keith Frost (keith.l.frost at gmail.com)
Date: Fri Jul 27 20:42:43 EDT 2007

Well, I'm still not sure what's happening, but here's what I've been
able to figure out so far.
The sqlite3 API includes a function
int sqlite3_get_table(
  sqlite3*,               /* An open database */
  const char *sql,       /* SQL to be executed */
  char ***resultp,       /* Result written to a char *[]  that this points to */
  int *nrow,             /* Number of result rows written here */
  int *ncolumn,          /* Number of result columns written here */
  char **errmsg          /* Error msg written here */

In sqlite.ss, the planet interface defines

  (define (select db sql)
    (let ([result_ptr_ptr
           (wrap-finalizer (malloc _string_array_ptr)
                           (lambda (ptr)
                             (when ptr
                                (ptr-ref ptr _string_array)))))]
          [row-count_ptr (malloc _int_ptr)]
          [column-count_ptr (malloc _int_ptr)])
      (when (handle-status
             (sqlite3_get_table (db-handle db)
                                (db-_errMsg_ptr db)))
         (add1 (ptr-ref row-count_ptr _int))
         (ptr-ref column-count_ptr _int)
         (make-cvector* (ptr-ref result_ptr_ptr _string_array)
                        (* (+ (ptr-ref row-count_ptr _int) 1)
                           (ptr-ref column-count_ptr _int)))))))

And it seems that some time between the calling of sqlite3_get_table,
and the extraction of some of the results with
cvector->list-of-vector, the block of memory pointed to by
result_ptr_ptr (which is apparently malloc'd by the sqlite3 library,
along with the space for the strings to which it points) can get
clobbered.  This seems to be what's happening, and I guess it's
plausible that 3m might do this, but what I don't know is how to fix
it.  Can anybody here give me another clue?


Keith F.

Posted on the users mailing list.