Browse Source

leak fixes

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@526 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/tags/lighttpd-1.4.2
Jan Kneschke 16 years ago
parent
commit
6517c89d4a
  1. 3
      src/.cvsignore
  2. 25
      src/configfile.c
  3. 66
      src/configparser.y
  4. 3
      src/data_array.c
  5. 5
      src/data_config.c
  6. 3
      src/data_count.c
  7. 4
      src/data_fastcgi.c
  8. 2
      src/data_integer.c
  9. 4
      src/data_string.c
  10. 11
      src/mod_redirect.c

3
src/.cvsignore

@ -4,9 +4,12 @@ spawn-fcgi
chunk
lemon
lighttpd
*.loT
*.exe
.deps
.libs
array
mod_ssi_exprparser.c
mod_ssi_exprparser.h
configparser.c
configparser.h

25
src/configfile.c

@ -529,7 +529,7 @@ static int config_tokenizer(server *srv, tokenizer_t *t, int *token_id, buffer *
case '\r':
if (t->in_brace == 0) {
int done = 0;
while (!done) {
while (!done && t->offset < t->size) {
switch (t->input[t->offset]) {
case '\r':
case '\n':
@ -806,18 +806,16 @@ int config_parse_file(server *srv, config_t *context, const char *fn) {
token = buffer_init();
}
buffer_free(token);
if (ret != -1 && context->ok) {
/* add an EOL at EOF, better than say sorry */
buffer_copy_string(token, "(EOL)");
configparser(pParser, TK_EOL, token, context);
token = buffer_init_string("(END)");
configparser(pParser, TK_EOL, buffer_init_string("(EOL)"), context);
if (context->ok) {
configparser(pParser, 0, token, context);
token = buffer_init();
configparser(pParser, 0, NULL, context);
}
}
configparserFree(pParser, free);
buffer_free(token);
if (ret == -1) {
log_error_write(srv, __FILE__, __LINE__, "sb",
@ -844,7 +842,15 @@ static void context_init(server *srv, config_t *context) {
}
static void context_free(config_t *context) {
array_free(context->configs_stack);
size_t i;
array *a = context->configs_stack;
/* don't free elements */
for (i = 0; i < a->size; i++) {
a->data[i] = NULL;
}
array_free(a);
buffer_free(context->basedir);
}
@ -882,7 +888,8 @@ int config_read(server *srv, const char *fn) {
ret = config_parse_file(srv, &context, fn);
assert(0 != ret || context.configs_stack->used == 0);
/* remains nothing if parser is ok */
assert(!(0 == ret && context.ok && 0 != context.configs_stack->used));
context_free(&context);
if (0 != ret) {

66
src/configparser.y

@ -1,5 +1,4 @@
%token_prefix TK_
%token_type {buffer *}
%extra_argument {config_t *ctx}
%name configparser
@ -65,15 +64,13 @@ data_unset *configparser_merge_data(config_t *ctx, data_unset *op1, const data_u
data_string *ds = (data_string *)op1;
buffer_append_long(ds->value, ((data_integer*)op2)->value);
return op1;
}
else if (op1->type == TYPE_INTEGER && op2->type == TYPE_STRING) {
} else if (op1->type == TYPE_INTEGER && op2->type == TYPE_STRING) {
data_string *ds = data_string_init();
buffer_append_long(ds->value, ((data_integer*)op1)->value);
buffer_append_string_buffer(ds->value, ((data_string*)op2)->value);
op1->free(op1);
return (data_unset *)ds;
}
else {
} else {
fprintf(stderr, "data type mismatch, cannot be merge\n");
ctx->ok = 0;
op1->free(op1);
@ -119,32 +116,47 @@ input ::= metalines.
metalines ::= metalines metaline.
metalines ::= .
metaline ::= varline.
metaline ::= condlines EOL.
metaline ::= condlines(A) EOL. { A = NULL; }
metaline ::= include.
metaline ::= EOL.
%type value {data_unset *}
%type expression {data_unset *}
%type context_rvalue {data_unset *}
%type aelement {data_unset *}
%type aelements {array *}
%type array {array *}
%type condline {data_config *}
%type condlines {data_config *}
%type cond {config_cond_t }
%token_destructor { buffer_free($$); }
%type value {data_unset *}
%type expression {data_unset *}
%type aelement {data_unset *}
%type condline {data_config *}
%type condlines {data_config *}
%type aelements {array *}
%type array {array *}
%type key {buffer *}
%type cond {config_cond_t }
%destructor value { $$->free($$); }
%destructor expression { $$->free($$); }
%destructor aelement { $$->free($$); }
%destructor condline { $$->free((data_unset *)$$); }
%destructor condlines { $$->free((data_unset *)$$); }
%destructor aelements { array_free($$); }
%destructor array { array_free($$); }
%destructor key { buffer_free($$); }
%token_type {buffer *}
%token_destructor { buffer_free($$); }
varline ::= key(A) ASSIGN expression(B). {
buffer_copy_string_buffer(B->key, A);
if (NULL == array_get_element(ctx->current->value, B->key->ptr)) {
array_insert_unique(ctx->current->value, B);
B = NULL;
} else {
fprintf(stderr, "Duplicate config variable in conditional 1 %s: %s\n",
ctx->current->key->ptr, B->key->ptr);
ctx->ok = 0;
B->free(B);
B = NULL;
}
buffer_free(A);
A = NULL;
}
varline ::= key(A) APPEND expression(B). {
@ -177,8 +189,9 @@ key(A) ::= LKEY(B). {
if (strchr(B->ptr, '.') == NULL) {
A = buffer_init_string("var.");
buffer_append_string_buffer(A, B);
}
else {
buffer_free(B);
B = NULL;
} else {
A = B;
B = NULL;
}
@ -213,17 +226,20 @@ value(A) ::= STRING(B). {
A = (data_unset *)data_string_init();
buffer_copy_string_buffer(((data_string *)(A))->value, B);
buffer_free(B);
B = NULL;
}
value(A) ::= INTEGER(B). {
A = (data_unset *)data_integer_init();
((data_integer *)(A))->value = strtol(B->ptr, NULL, 10);
buffer_free(B);
B = NULL;
}
value(A) ::= array(B). {
A = (data_unset *)data_array_init();
array_free(((data_array *)(A))->value);
((data_array *)(A))->value = B;
B = NULL;
}
array(A) ::= LPARAN aelements(B) RPARAN. {
A = B;
@ -234,23 +250,28 @@ aelements(A) ::= aelements(C) COMMA aelement(B). {
if (buffer_is_empty(B->key) ||
NULL == array_get_element(C, B->key->ptr)) {
array_insert_unique(C, B);
B = NULL;
} else {
fprintf(stderr, "Duplicate array-key: %s\n",
B->key->ptr);
B->free(B);
ctx->ok = 0;
B->free(B);
B = NULL;
}
A = C;
C = NULL;
}
aelements(A) ::= aelements(C) COMMA. {
A = C;
C = NULL;
}
aelements(A) ::= aelement(B). {
A = array_init();
array_insert_unique(A, B);
B = NULL;
}
aelement(A) ::= expression(B). {
@ -260,6 +281,7 @@ aelement(A) ::= expression(B). {
aelement(A) ::= STRING(B) ARRAY_ASSIGN expression(C). {
buffer_copy_string_buffer(C->key, B);
buffer_free(B);
B = NULL;
A = C;
C = NULL;
@ -386,6 +408,10 @@ context ::= DOLLAR SRVVARNAME(B) LBRACKET STRING(C) RBRACKET cond(E) expression(
}
buffer_free(b);
buffer_free(B);
B = NULL;
buffer_free(C);
C = NULL;
D->free(D);
D = NULL;
}
@ -413,7 +439,7 @@ include ::= INCLUDE expression(A). {
ctx->ok = 0;
}
}
A->free(A);
}
A->free(A);
A = NULL;
}

3
src/data_array.c

@ -8,7 +8,8 @@ static data_unset *data_array_copy(const data_unset *s) {
data_array *src = (data_array *)s;
data_array *ds = data_array_init();
ds->key = buffer_init_buffer(src->key);
buffer_copy_string_buffer(ds->key, src->key);
array_free(ds->value);
ds->value = array_init_array(src->value);
return (data_unset *)ds;
}

5
src/data_config.c

@ -8,8 +8,9 @@ static data_unset *data_config_copy(const data_unset *s) {
data_config *src = (data_config *)s;
data_config *ds = data_config_init();
ds->key = buffer_init_buffer(src->key);
ds->comp_key = buffer_init_buffer(src->comp_key);
buffer_copy_string_buffer(ds->key, src->key);
buffer_copy_string_buffer(ds->comp_key, src->comp_key);
array_free(ds->value);
ds->value = array_init_array(src->value);
return (data_unset *)ds;
}

3
src/data_count.c

@ -8,7 +8,7 @@ static data_unset *data_count_copy(const data_unset *s) {
data_count *src = (data_count *)s;
data_count *ds = data_count_init();
ds->key = buffer_init_buffer(src->key);
buffer_copy_string_buffer(ds->key, src->key);
ds->count = src->count;
return (data_unset *)ds;
}
@ -56,7 +56,6 @@ data_count *data_count_init(void) {
ds->key = buffer_init();
ds->count = 1;
ds->copy = data_count_copy;
ds->copy = data_count_copy;
ds->free = data_count_free;
ds->reset = data_count_reset;

4
src/data_fastcgi.c

@ -9,8 +9,8 @@ static data_unset *data_fastcgi_copy(const data_unset *s) {
data_fastcgi *src = (data_fastcgi *)s;
data_fastcgi *ds = data_fastcgi_init();
ds->key = buffer_init_buffer(src->key);
ds->host = buffer_init_buffer(src->host);
buffer_copy_string_buffer(ds->key, src->key);
buffer_copy_string_buffer(ds->host, src->host);
return (data_unset *)ds;
}

2
src/data_integer.c

@ -8,7 +8,7 @@ static data_unset *data_integer_copy(const data_unset *s) {
data_integer *src = (data_integer *)s;
data_integer *ds = data_integer_init();
ds->key = buffer_init_buffer(src->key);
buffer_copy_string_buffer(ds->key, src->key);
ds->value = src->value;
return (data_unset *)ds;
}

4
src/data_string.c

@ -9,8 +9,8 @@ static data_unset *data_string_copy(const data_unset *s) {
data_string *src = (data_string *)s;
data_string *ds = data_string_init();
ds->key = buffer_init_buffer(src->key);
ds->value = buffer_init_buffer(src->value);
buffer_copy_string_buffer(ds->key, src->key);
buffer_copy_string_buffer(ds->value, src->value);
return (data_unset *)ds;
}

11
src/mod_redirect.c

@ -58,6 +58,17 @@ FREE_FUNC(mod_redirect_free) {
buffer_free(p->match_buf);
buffer_free(p->location);
if (p->config_storage) {
size_t i;
for (i = 0; i < srv->config_context->used; i++) {
plugin_config *s = p->config_storage[i];
pcre_keyvalue_buffer_free(s->redirect);
free(s);
}
free(p->config_storage);
}
free(p);

Loading…
Cancel
Save