array.c: improve array_get_unused_element to check data type; fix mem leak if unused_element didn't find a matching entry (fixes #2145)

- the "mem leak" could only be triggered if you use different entry
   types in the same array (this wasn't supported by
   array_get_unused_element) or didn't call array_get_unused_element
   before creating new entries.

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2750 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/tags/lighttpd-1.4.27
Stefan Bühler 13 years ago
parent cf5fcf953d
commit 12f375f3b1

@ -25,6 +25,7 @@ NEWS
* mod_accesslog: optimize accesslog_append_escaped (fixes #2236, thx crypt)
* autotools: don't recreate parser files with lemon after lemon rebuild
* openssl: silence annoying error messages for errno==0 (fixes #2213)
* array.c: improve array_get_unused_element to check data type; fix mem leak if unused_element didn't find a matching entry (fixes #2145)
- 1.4.26 - 2010-02-07
* Fix request parser to handle packets with splitted \r\n\r\n (fixes #2105)

@ -130,20 +130,21 @@ data_unset *array_get_element(array *a, const char *key) {
data_unset *array_get_unused_element(array *a, data_type_t t) {
data_unset *ds = NULL;
unsigned int i;
UNUSED(t);
for (i = a->used; i < a->size; i++) {
if (a->data[i] && a->data[i]->type == t) {
ds = a->data[i];
if (a->size == 0) return NULL;
/* make empty slot at a->used for next insert */
a->data[i] = a->data[a->used];
a->data[a->used] = NULL;
if (a->used == a->size) return NULL;
if (a->data[a->used]) {
ds = a->data[a->used];
a->data[a->used] = NULL;
return ds;
}
}
return ds;
return NULL;
}
void array_set_key_value(array *hdrs, const char *key, size_t key_len, const char *value, size_t val_len) {
@ -224,6 +225,9 @@ int array_insert_unique(array *a, data_unset *str) {
ndx = (int) a->used;
/* make sure there is nothing here */
if (a->data[ndx]) a->data[ndx]->free(a->data[ndx]);
a->data[a->used++] = str;
if (pos != ndx &&

Loading…
Cancel
Save