A loop such as the following leaks memory in libdbi 0.8.3:

        for (n = 0; n < 100000; n++) {

        res = dbi_conn_query(conn, "SELECT * FROM foo;");

        if (!dbi_result_first_row(res)) {
                fprintf(stderr, "dbi_result_first_row() failed.\n");
                exit(1);
        }

        for (i = 0; i < 2; i++) {
                do {
                        val = dbi_result_get_int(res, "val");
                        if (n == 0)
                          printf("val: %d\n", val);

                } while (dbi_result_next_row(res));

                /* Rewind for the next iteration of the for() loop */
                if (!dbi_result_first_row(res)) {
                        fprintf(stderr, "dbi_result_first_row() failed.\n");
                        exit(1);
                }
        }

        dbi_result_free(res);

        }


This patch appears to fix it:


diff -Naur libdbi-0.8.3.orig/src/dbi_result.c libdbi-0.8.3/src/dbi_result.c
--- libdbi-0.8.3.orig/src/dbi_result.c  2008-01-23 11:37:36.000000000 -0500
+++ libdbi-0.8.3/src/dbi_result.c       2011-09-06 20:51:34.610449576 -0400
@@ -1533,7 +1533,7 @@
 }
 
 static int _is_row_fetched(dbi_result_t *result, unsigned long long row) {
-  if (!result->rows || (row >= result->numrows_matched)) return -1;
+  if (!result->rows || (row > result->numrows_matched)) return -1;
   return !(result->rows[row] == NULL);
 }
 


This was discovered by some folks at Bull, who also deserve credit for
the patch, but I don't have a full name.

                        regards, tom lane

------------------------------------------------------------------------------
Using storage to extend the benefits of virtualization and iSCSI
Virtualization increases hardware utilization and delivers a new level of
agility. Learn what those decisions are and how to modernize your storage 
and backup environments for virtualization.
http://www.accelacomm.com/jaw/sfnl/114/51434361/
_______________________________________________
libdbi-devel mailing list
libdbi-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libdbi-devel

Reply via email to