I received a number of warnings about zero-byte allocations when running
an application that uses libdbi under valgrind.

It seems that the memory allocated in _dbd_result_set_numfields is never
freed in dbi_result_free if result->numfields is zero. Yet, calloc seems
to allocate some resources even if the first argument is zero, therefore
leading to a slow memory leak.

Below is a suggested patch to fix _dbd_result_set_numfields.

        Sami


--- dbd_helper.c.orig   2005-12-07 18:01:26.000000000 +0200
+++ dbd_helper.c        2005-12-07 17:45:43.000000000 +0200
@@ -85,9 +85,11 @@
 
 void _dbd_result_set_numfields(dbi_result_t *result, unsigned int numfields) {
        result->numfields = numfields;
-       result->field_names = calloc(numfields, sizeof(char *));
-       result->field_types = calloc(numfields, sizeof(unsigned short));
-       result->field_attribs = calloc(numfields, sizeof(unsigned int *));
+       if (numfields > 0) {
+               result->field_names = calloc(numfields, sizeof(char *));
+               result->field_types = calloc(numfields, sizeof(unsigned short));
+               result->field_attribs = calloc(numfields, sizeof(unsigned int 
*));
+       }
 }
 
 void _dbd_result_add_field(dbi_result_t *result, unsigned int idx, char *name, 
unsigned short type, unsigned int attribs) {


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
libdbi-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libdbi-devel

Reply via email to