From aca394bf0cea646cc78c5e0e8a72cc5d1f21452b Mon Sep 17 00:00:00 2001 From: Tilghman Lesher Date: Mon, 4 Aug 2008 16:34:04 +0000 Subject: [PATCH] HTTP module memory leaks (closes issue #13230) Reported by: eliel Patches: res_http_post_leak.patch uploaded by eliel (license 64) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@135476 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- include/asterisk/http.h | 6 +++++- main/http.c | 6 ++++++ res/res_http_post.c | 9 ++++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/include/asterisk/http.h b/include/asterisk/http.h index 1f46b1eed1..218ac3f1ae 100644 --- a/include/asterisk/http.h +++ b/include/asterisk/http.h @@ -87,9 +87,13 @@ struct ast_http_uri { unsigned int supports_get:1; /*! This handler accepts POST requests */ unsigned int supports_post:1; + /*! Structure is malloc'd */ + unsigned int mallocd:1; + /*! Data structure is malloc'd */ + unsigned int dmallocd:1; /*! Data to bind to the uri if needed */ void *data; - /*! Key to be used for unlinking if multipile URIs registerd */ + /*! Key to be used for unlinking if multiple URIs registered */ const char *key; }; diff --git a/main/http.c b/main/http.c index bb6ae61219..d08b17fa4b 100644 --- a/main/http.c +++ b/main/http.c @@ -389,6 +389,12 @@ void ast_http_uri_unlink_all_with_key(const char *key) if (!strcmp(urih->key, key)) { AST_RWLIST_REMOVE_CURRENT(entry); } + if (urih->dmallocd) { + ast_free(urih->data); + } + if (urih->mallocd) { + ast_free(urih); + } } AST_RWLIST_TRAVERSE_SAFE_END AST_RWLIST_UNLOCK(&uris); diff --git a/res/res_http_post.c b/res/res_http_post.c index f1ae7a7da5..2e4a20a1d4 100644 --- a/res/res_http_post.c +++ b/res/res_http_post.c @@ -289,12 +289,15 @@ static int __ast_http_post_load(int reload) struct ast_str *ds; if (!(urih = ast_calloc(sizeof(*urih), 1))) { + ast_config_destroy(cfg); return -1; } - if (!(ds = ast_str_create(32))) + if (!(ds = ast_str_create(32))) { + ast_free(urih); + ast_config_destroy(cfg); return -1; - + } urih->description = ast_strdup("HTTP POST mapping"); urih->uri = ast_strdup(v->name); @@ -305,6 +308,7 @@ static int __ast_http_post_load(int reload) urih->supports_post = 1; urih->callback = http_post_callback; urih->key = __FILE__; + urih->mallocd = urih->dmallocd = 1; ast_http_uri_link(urih); } @@ -323,7 +327,6 @@ static int unload_module(void) static int reload(void) { - __ast_http_post_load(1); return AST_MODULE_LOAD_SUCCESS;