HTTP module memory leaks
[asterisk/asterisk.git] / res / res_http_post.c
index bcf2e0d..2e4a20a 100644 (file)
@@ -203,6 +203,8 @@ static struct ast_str *http_post_callback(struct ast_tcptls_session_instance *se
        }
 
        for (var = headers; var; var = var->next) {
+               fprintf(f, "%s: %s\r\n", var->name, var->value);
+
                if (!strcasecmp(var->name, "Content-Length")) {
                        if ((sscanf(var->value, "%u", &content_len)) != 1) {
                                ast_log(LOG_ERROR, "Invalid Content-Length in POST request!\n");
@@ -211,11 +213,11 @@ static struct ast_str *http_post_callback(struct ast_tcptls_session_instance *se
                                return NULL;
                        }
                        ast_debug(1, "Got a Content-Length of %d\n", content_len);
-               } else if (!strcasecmp(var->name, "Content-Type")) {
-                       fprintf(f, "Content-Type: %s\r\n\r\n", var->value);
                }
        }
 
+       fprintf(f, "\r\n");
+
        for (res = sizeof(buf); content_len; content_len -= res) {
                if (content_len < res) {
                        res = content_len;
@@ -245,12 +247,14 @@ static struct ast_str *http_post_callback(struct ast_tcptls_session_instance *se
 
        if (!(message_count = process_message(message, post_dir->str))) {
                ast_log(LOG_ERROR, "Invalid MIME data, found no parts!\n");
-
+               g_object_unref(message);
                return ast_http_error((*status = 400),
                                      (*title = ast_strdup("Bad Request")),
                                      NULL, "The was an error parsing the request.");
        }
 
+       g_object_unref(message);
+
        return ast_http_error((*status = 200),
                              (*title = ast_strdup("OK")),
                              NULL, "File successfully uploaded.");
@@ -285,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);
@@ -301,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);
                }
@@ -319,7 +327,6 @@ static int unload_module(void)
 
 static int reload(void)
 {
-
        __ast_http_post_load(1);
 
        return AST_MODULE_LOAD_SUCCESS;