Fix a variety of memory leaks
[asterisk/asterisk.git] / res / res_calendar_exchange.c
index 2c121bc..e7beeaf 100644 (file)
        <depend>neon</depend>
        <depend>ical</depend>
        <depend>iksemel</depend>
+       <support_level>core</support_level>
 ***/
+
 #include "asterisk.h"
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
-#include <ical.h>
+#include <libical/ical.h>
 #include <ne_session.h>
 #include <ne_uri.h>
 #include <ne_request.h>
 #include <ne_auth.h>
+#include <ne_redirect.h>
 #include <iksemel.h>
 
 #include "asterisk/module.h"
@@ -402,6 +405,7 @@ static struct ast_str *exchangecal_request(struct exchangecal_pvt *pvt, const ch
        ne_add_request_header(req, "Content-type", "text/xml");
 
        ret = ne_request_dispatch(req);
+       ne_request_destroy(req);
 
        if (ret != NE_OK || !ast_str_strlen(response)) {
                ast_log(LOG_WARNING, "Unknown response to CalDAV calendar %s, request %s to %s: %s\n", pvt->owner->name, method, pvt->url, ne_get_error(pvt->session));
@@ -429,9 +433,8 @@ static int exchangecal_write_event(struct ast_calendar_event *event)
                return -1;
        }
        if (!(body = ast_str_create(512)) ||
-               !(subdir = ast_str_create(32)) ||
-               !(response = ast_str_create(512))) {
-               ast_log(LOG_ERROR, "Could not allocate memory for request and response!\n");
+               !(subdir = ast_str_create(32))) {
+               ast_log(LOG_ERROR, "Could not allocate memory for request!\n");
                goto write_cleanup;
        }
 
@@ -501,9 +504,10 @@ static int exchangecal_write_event(struct ast_calendar_event *event)
        ast_verb(0, "\n\n%s\n\n", ast_str_buffer(body));
        ast_str_set(&subdir, 0, "/Calendar/%s.eml", ast_str_buffer(uid));
 
-       response = exchangecal_request(event->owner->tech_pvt, "PROPPATCH", body, subdir);
+       if ((response = exchangecal_request(event->owner->tech_pvt, "PROPPATCH", body, subdir))) {
+               ret = 0;
+       }
 
-       ret = 0;
 write_cleanup:
        if (uid) {
                ast_free(uid);
@@ -693,6 +697,7 @@ static void *exchangecal_load_calendar(void *void_data)
        }
 
        pvt->session = ne_session_create(pvt->uri.scheme, pvt->uri.host, pvt->uri.port);
+       ne_redirect_register(pvt->session);
        ne_set_server_auth(pvt->session, auth_credentials, pvt);
        if (!strcasecmp(pvt->uri.scheme, "https")) {
                ne_ssl_trust_default_ca(pvt->session);
@@ -753,7 +758,8 @@ static int unload_module(void)
        return 0;
 }
 
-AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Asterisk MS Exchange Calendar Integration",
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Asterisk MS Exchange Calendar Integration",
                .load = load_module,
                .unload = unload_module,
+               .load_pri = AST_MODPRI_DEVSTATE_PLUGIN,
        );