summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Bühler <stbuehler@web.de>2010-08-05 21:08:23 +0000
committerStefan Bühler <stbuehler@web.de>2010-08-05 21:08:23 +0000
commit12f375f3b186a6abd38874a96ec0f80fc8e7805b (patch)
tree7f1b10d13f2074290646b068ca5c32586accb68d
parentcf5fcf953d1cd6a9b68c0ef7ca1f34a3c3bfd7d7 (diff)
downloadlighttpd-git-12f375f3b186a6abd38874a96ec0f80fc8e7805b.tar.gz
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
-rw-r--r--NEWS1
-rw-r--r--src/array.c22
2 files changed, 14 insertions, 9 deletions
diff --git a/NEWS b/NEWS
index f42ce420..846a9f49 100644
--- a/NEWS
+++ b/NEWS
@@ -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)
diff --git a/src/array.c b/src/array.c
index e93906b1..12437d4f 100644
--- a/src/array.c
+++ b/src/array.c
@@ -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 &&