|
From: James S. <se...@di...> - 2005-05-19 00:44:32
|
Sorry for the repeat post, but I want to make sure this doesn't slip
though the cracks (it hasn't been applied to the repository).
-Jim
-------- Original Message --------
Subject: [libdbi-devel] [PATCH] Memory Leak Fix
Date: Tue, 22 Mar 2005 00:39:34 -0700
From: James Sella <se...@di...>
To: lib...@li...
The attached patch fixes a memory leak within libdbi. The memory leak
can be seen if you perform a query, seek and then free the result set.
It can be applied as follows, within the libdbi directory (newest cvs
checkout):
cd libdbi
patch -p1 < libdbi-leak-fix.patch
The function call _dbd_row_allocate() within src/dbd_helper.c, allocate
memory for row->field_flags. The function call _free_result_rows()
within src/dbi_result.c should release it, however doesn't.
[src/dbd_helper.c]
dbi_row_t *_dbd_row_allocate(unsigned short numfields) {
dbi_row_t *row = malloc(sizeof(dbi_row_t));
if (!row) return NULL;
row->field_values = calloc(numfields, sizeof(dbi_data_t));
row->field_sizes = calloc(numfields, sizeof(unsigned long long));
/* Allocated below */
row->field_flags = calloc(numfields, sizeof(unsigned char));
return row;
}
[src/dbi_result.c]
static void _free_result_rows(dbi_result_t *result) {
unsigned long long rowidx = 0;
unsigned short fieldidx = 0;
for (rowidx = 0; rowidx <= result->numrows_matched; rowidx++) {
if (!result->rows[rowidx]) continue;
for (fieldidx = 0; fieldidx < result->numfields; fieldidx++) {
if (((result->field_types[fieldidx] == DBI_TYPE_STRING) ||
(result->field_types[fieldidx] == DBI_TYPE_BINARY)) &&
result->rows[rowidx]->field_values[fieldidx].d_string) {
free(result->rows[rowidx]->field_values[fieldidx].d_string);
}
}
free(result->rows[rowidx]->field_values);
free(result->rows[rowidx]->field_sizes);
/* Should be free'd here. */
free(result->rows[rowidx]);
}
free(result->rows);
}
-Jim
|