|
From: Sami T. <sa...@to...> - 2005-12-07 16:20:15
|
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) {
|