|
From: Markus H. <mar...@mh...> - 2011-09-20 21:53:54
|
Hi,
I've fiddled a little with your testcase and the suggested fix. My
results are as follows using the mysql driver (my loop ran only one
tenth of the suggested cycles, so your values may be even higher):
before fix:
==3410== LEAK SUMMARY:
==3410== definitely lost: 240,384 bytes in 10,004 blocks
==3410== indirectly lost: 170,032 bytes in 30,004 blocks
==3410== possibly lost: 0 bytes in 0 blocks
==3410== still reachable: 8,594 bytes in 7 blocks
==3410== suppressed: 0 bytes in 0 blocks
after fix:
==3541== LEAK SUMMARY:
==3541== definitely lost: 384 bytes in 4 blocks
==3541== indirectly lost: 32 bytes in 4 blocks
==3541== possibly lost: 0 bytes in 0 blocks
==3541== still reachable: 8,594 bytes in 7 blocks
==3541== suppressed: 0 bytes in 0 blocks
So there is a clear improvement although some memory is still lost.
Even worse, I've discovered another leak in the sqlite3 driver (or in
sqlite?) with this testcase, so there is some more work to do.
I've checked in the suggested fix. Thanks for bringing this to my attention.
regards,
Markus
Quoting Tom Lane <tg...@ss...>:
> 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
> lib...@li...
> https://lists.sourceforge.net/lists/listinfo/libdbi-devel
--
Markus Hoenicka
http://www.mhoenicka.de
AQ score 38
|