1
0
Fork 0

various memory leak fixes

This commit is contained in:
bagyenda 2008-04-18 12:32:31 +00:00
parent ee5c86878d
commit e78739a3a1
10 changed files with 69 additions and 47 deletions

View File

@ -1,3 +1,5 @@
2008-04-18 P. A. Bagyenda <bagyenda@dsmagic.com>
* Various memory leak fixes (thanks to Monachin Eric @ Skycore)
2008-04-11 P. A. Bagyenda <bagyenda@dsmagic.com> 2008-04-11 P. A. Bagyenda <bagyenda@dsmagic.com>
* Added no-sender-address config to mmsc section: Allows you to * Added no-sender-address config to mmsc section: Allows you to
* suppress SenderAddress SOAP/XML tag * suppress SenderAddress SOAP/XML tag

View File

@ -229,11 +229,12 @@ void mms_cfg_destroy(mCfg *cfg)
for (i = 0, l = dict_keys(cfg->grps), n = gwlist_len(l); i < n; i++) { for (i = 0, l = dict_keys(cfg->grps), n = gwlist_len(l); i < n; i++) {
Octstr *grpname = gwlist_get(l, i); Octstr *grpname = gwlist_get(l, i);
void *val = dict_get(cfg->grps, grpname); void *val = dict_get(cfg->grps, grpname);
if (is_multigroup(grpname)) { if (is_multigroup(grpname)) { /* item is a list. */
List *gl = val; List *gl = val;
int j, m = gwlist_len(gl); int j, m = gwlist_len(gl);
for (j = 0; j < m; j++) for (j = 0; j < m; j++)
mGrp_destroy(gwlist_get(gl, j)); mGrp_destroy(gwlist_get(gl, j));
gwlist_destroy(gl, NULL);
} else } else
mGrp_destroy(val); mGrp_destroy(val);
} }

View File

@ -673,7 +673,7 @@ static Octstr *headers_to_soapxml(List *hdrs, MM7Version_t *ver)
int mm7_soapmsg_to_httpmsg(MSoapMsg_t *m, MM7Version_t *ver, List **hdrs, Octstr **body) int mm7_soapmsg_to_httpmsg(MSoapMsg_t *m, MM7Version_t *ver, List **hdrs, Octstr **body)
{ {
MIMEEntity *mime; MIMEEntity *mime;
Octstr *ctype, *s; Octstr *ctype = NULL, *s;
List *headers; List *headers;
mime = mime_entity_create(); mime = mime_entity_create();
@ -749,6 +749,7 @@ int mm7_soapmsg_to_httpmsg(MSoapMsg_t *m, MM7Version_t *ver, List **hdrs, Octstr
debug("mms2soap", 0, "SOAP MSG is: %s", octstr_get_cstr(*body)); debug("mms2soap", 0, "SOAP MSG is: %s", octstr_get_cstr(*body));
mime_entity_destroy(mime); mime_entity_destroy(mime);
octstr_destroy(ctype);
return 0; return 0;
} }

View File

@ -1006,7 +1006,7 @@ static int encode_msgheaders(Octstr *os, List *hdrs)
/* Does basic fixups on a message. */ /* Does basic fixups on a message. */
static int fixup_msg(MmsMsg *m, Octstr *from) static int fixup_msg(MmsMsg *m, Octstr *from)
{ {
Octstr *ver; Octstr *ver = NULL;
Octstr *s = NULL; Octstr *s = NULL;
if (!m) if (!m)
return -1; return -1;
@ -1027,7 +1027,7 @@ static int fixup_msg(MmsMsg *m, Octstr *from)
/* Check for from. */ /* Check for from. */
if (from && (s = http_header_value(m->headers, octstr_imm("From"))) == NULL) if (from && (s = http_header_value(m->headers, octstr_imm("From"))) == NULL)
http_header_add(m->headers, "From", octstr_get_cstr(from)); http_header_add(m->headers, "From", octstr_get_cstr(from));
else if (s) else
octstr_destroy(s); octstr_destroy(s);
/* Check for date. */ /* Check for date. */
@ -1043,8 +1043,8 @@ static int fixup_msg(MmsMsg *m, Octstr *from)
if ((s = http_header_value(m->headers, octstr_imm("X-Mms-Transaction-ID"))) == NULL) { if ((s = http_header_value(m->headers, octstr_imm("X-Mms-Transaction-ID"))) == NULL) {
if (m->message_type != MMS_MSGTYPE_RETRIEVE_CONF) if (m->message_type != MMS_MSGTYPE_RETRIEVE_CONF)
http_header_add(m->headers, "X-Mms-Transaction-ID", "00001"); http_header_add(m->headers, "X-Mms-Transaction-ID", "00001");
} else
octstr_destroy(s); octstr_destroy(s);
}
#if 0 /* This will be done elsewhere. */ #if 0 /* This will be done elsewhere. */
/* Check for msgid, put in if missing. */ /* Check for msgid, put in if missing. */
if ((s = http_header_value(m->headers, octstr_imm("Message-ID"))) == NULL) if ((s = http_header_value(m->headers, octstr_imm("Message-ID"))) == NULL)
@ -1077,6 +1077,7 @@ static int fixup_msg(MmsMsg *m, Octstr *from)
http_header_remove_all(m->headers, "Content-Type"); /* Just in case, particularly from mime! */ http_header_remove_all(m->headers, "Content-Type"); /* Just in case, particularly from mime! */
break; break;
} }
octstr_destroy(ver);
return 0; return 0;
} }
@ -1222,10 +1223,10 @@ int mms_messagetype(MmsMsg *msg)
} }
static void convert_mime_msg(MIMEEntity *m) static int convert_mime_msg(MIMEEntity *m)
{ {
int i, n; int i, n, res = 0;
Octstr *content_type = NULL, *params; Octstr *content_type = NULL, *params = NULL;
char *s = NULL; char *s = NULL;
List *h = mime_entity_headers(m); List *h = mime_entity_headers(m);
@ -1241,8 +1242,8 @@ static void convert_mime_msg(MIMEEntity *m)
else if (octstr_str_compare(content_type, else if (octstr_str_compare(content_type,
"application/vnd.wap.multipart.mixed") == 0) "application/vnd.wap.multipart.mixed") == 0)
s = "multipart/mixed"; s = "multipart/mixed";
octstr_destroy(content_type);
} }
if (s) { if (s) {
Octstr *value; Octstr *value;
@ -1260,21 +1261,29 @@ static void convert_mime_msg(MIMEEntity *m)
mime_replace_headers(m,h); mime_replace_headers(m,h);
octstr_destroy(value); octstr_destroy(value);
res = 1;
} }
http_destroy_headers(h); http_destroy_headers(h);
octstr_destroy(params);
if ((n = mime_entity_num_parts(m)) > 0) if ((n = mime_entity_num_parts(m)) > 0)
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
MIMEEntity *x = mime_entity_get_part(m, i); MIMEEntity *x = mime_entity_get_part(m, i);
convert_mime_msg(x); int xres = convert_mime_msg(x);
mime_entity_replace_part(m, i, x); if (xres) {
mime_entity_replace_part(m, i, x);
res = 1;
}
mime_entity_destroy(x);
} }
octstr_destroy(params);
octstr_destroy(content_type);
return res;
} }
static void unconvert_mime_msg(MIMEEntity *m) static int unconvert_mime_msg(MIMEEntity *m)
{ {
int i, n; int i, n, res = 0;
Octstr *content_type, *params; Octstr *content_type, *params;
char *s = NULL; char *s = NULL;
List *h = mime_entity_headers(m); List *h = mime_entity_headers(m);
@ -1298,7 +1307,7 @@ static void unconvert_mime_msg(MIMEEntity *m)
mime_entity_set_body(m, x); mime_entity_set_body(m, x);
octstr_destroy(x); octstr_destroy(x);
} }
octstr_destroy(content_type); res = 1;
} }
if (s) if (s)
@ -1306,13 +1315,18 @@ static void unconvert_mime_msg(MIMEEntity *m)
mime_replace_headers(m, h); mime_replace_headers(m, h);
http_destroy_headers(h); http_destroy_headers(h);
octstr_destroy(params); octstr_destroy(params);
octstr_destroy(content_type);
if ((n = mime_entity_num_parts(m)) > 0) if ((n = mime_entity_num_parts(m)) > 0)
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
MIMEEntity *x = mime_entity_get_part(m, i); MIMEEntity *x = mime_entity_get_part(m, i);
unconvert_mime_msg(x); int xres = unconvert_mime_msg(x);
mime_entity_replace_part(m, i, x); if (xres) {
mime_entity_replace_part(m, i, x);
res = 1;
}
mime_entity_destroy(x);
} }
return res;
} }

View File

@ -223,8 +223,6 @@ static MmsEnvelope *mms_queue_readenvelope(char *qf, char *mms_queuedir, int sho
NULL, NULL,
qf, qf,
sizeof (struct qfile_t), NULL); sizeof (struct qfile_t), NULL);
e->to = gwlist_create();
qfs = e->qfs_data; qfs = e->qfs_data;
qfs->fd = fd; qfs->fd = fd;

View File

@ -1054,7 +1054,7 @@ static int format_special(MIMEEntity *m,
if ((n = mime_entity_num_parts(m)) > 0) { if ((n = mime_entity_num_parts(m)) > 0) {
int presindex = -1; int presindex = -1;
Octstr *presbody; Octstr *presbody = NULL;
Octstr *start = http_header_value(params_h, octstr_imm("start")); Octstr *start = http_header_value(params_h, octstr_imm("start"));
for (i = 0; i<n; i++) {/* format sub-parts, find presentation part too */ for (i = 0; i<n; i++) {/* format sub-parts, find presentation part too */
@ -1073,9 +1073,9 @@ static int format_special(MIMEEntity *m,
presindex = i; presindex = i;
if (ctype) octstr_destroy(ctype); octstr_destroy(ctype);
if (charset) octstr_destroy(charset); octstr_destroy(charset);
if (cid) octstr_destroy(cid); octstr_destroy(cid);
format_special(x, trans_smil, txtmsg, htmlmsg, counter); format_special(x, trans_smil, txtmsg, htmlmsg, counter);
mime_entity_replace_part(m, i, x); mime_entity_replace_part(m, i, x);
@ -1084,7 +1084,7 @@ static int format_special(MIMEEntity *m,
mime_entity_destroy(x); mime_entity_destroy(x);
} }
if (start) octstr_destroy(start); octstr_destroy(start);
if (trans_smil && presindex >= 0) { /* Reformat. */ if (trans_smil && presindex >= 0) { /* Reformat. */
MIMEEntity *x, *pres; MIMEEntity *x, *pres;
@ -1105,7 +1105,7 @@ static int format_special(MIMEEntity *m,
Octstr *y, *loc, *cidurl; Octstr *y, *loc, *cidurl;
List *cparamsl; List *cparamsl;
if (i == presindex) continue; /* Skip the presentation param. */ if (i == presindex) goto loop; /* Skip the presentation param. */
hx = mime_entity_headers(x); hx = mime_entity_headers(x);
cid = _x_get_content_id(hx); cid = _x_get_content_id(hx);
@ -1172,15 +1172,17 @@ static int format_special(MIMEEntity *m,
mime_entity_replace_part(m, i, x); mime_entity_replace_part(m, i, x);
http_destroy_headers(hx); http_destroy_headers(hx);
mime_entity_destroy(x);
if (y) octstr_destroy(y); octstr_destroy(y);
if (loc) octstr_destroy(loc); octstr_destroy(loc);
if (ctype) octstr_destroy(ctype); octstr_destroy(ctype);
if (cidurl) octstr_destroy(cidurl); octstr_destroy(cidurl);
if (pname) octstr_destroy(pname); octstr_destroy(pname);
octstr_destroy(cid); octstr_destroy(cid);
loop:
mime_entity_destroy(x);
} }
pres = mime_entity_get_part(m,presindex); pres = mime_entity_get_part(m,presindex);
@ -1240,6 +1242,7 @@ static int format_special(MIMEEntity *m,
mime_entity_replace_part(m, presindex, pres); mime_entity_replace_part(m, presindex, pres);
mime_entity_destroy(pres); mime_entity_destroy(pres);
octstr_destroy(presbody);
octstr_destroy(btxt); octstr_destroy(btxt);
} }
goto done; goto done;
@ -1344,12 +1347,12 @@ static int format_special(MIMEEntity *m,
mime_replace_headers(m, headers); mime_replace_headers(m, headers);
http_destroy_headers(headers); http_destroy_headers(headers);
} }
if (content_type)
octstr_destroy(content_type); octstr_destroy(content_type);
octstr_destroy(params);
if (params_h) if (params_h)
http_destroy_headers(params_h); http_destroy_headers(params_h);
if (cmd) octstr_destroy(cmd);
octstr_destroy(cmd);
if (tmpf[0]) if (tmpf[0])
unlink(tmpf); unlink(tmpf);

View File

@ -1224,6 +1224,7 @@ void strip_boundary_element(List *headers, char *s)
if (ctype != value) if (ctype != value)
octstr_destroy(ctype); octstr_destroy(ctype);
octstr_destroy(value); octstr_destroy(value);
octstr_destroy(params);
} }

View File

@ -1154,6 +1154,7 @@ done:
octstr_destroy(xfrom); octstr_destroy(xfrom);
octstr_destroy(subject); octstr_destroy(subject);
octstr_destroy(otransid); octstr_destroy(otransid);
octstr_destroy(turl);
if (me) if (me)
mime_entity_destroy(me); mime_entity_destroy(me);

View File

@ -46,7 +46,7 @@ int mms_load_mmsbox_settings(mCfg *cfg, gwthread_func_t *mmsc_handler_func)
{ {
mCfgGrp *grp = mms_cfg_get_single(cfg, octstr_imm("mbuni")); mCfgGrp *grp = mms_cfg_get_single(cfg, octstr_imm("mbuni"));
mCfgGrp *cgrp = mms_cfg_get_single(cfg, octstr_imm("core")); mCfgGrp *cgrp = mms_cfg_get_single(cfg, octstr_imm("core"));
Octstr *gdir, *s, *tmp; Octstr *gdir = NULL, *s, *tmp;
int send_port_ssl = 0; int send_port_ssl = 0;
List *l; List *l;
int i, n, xx; int i, n, xx;
@ -184,8 +184,8 @@ int mms_load_mmsbox_settings(mCfg *cfg, gwthread_func_t *mmsc_handler_func)
m->id = _mms_cfg_getx(x, octstr_imm("id")); m->id = _mms_cfg_getx(x, octstr_imm("id"));
if (octstr_len(m->id) < 1) if (octstr_len(m->id) < 1)
panic(0,"Missing required value `id' in config file!"); panic(0,"Missing required value `id' in config file!");
m->group_id = _mms_cfg_getx(x, octstr_imm("group-id")); m->group_id = mms_cfg_get(x, octstr_imm("group-id"));
if (octstr_len(m->group_id) < 1) if (m->group_id == NULL)
m->group_id = octstr_duplicate(m->id); m->group_id = octstr_duplicate(m->id);
m->mmsc_url = _mms_cfg_getx(x, octstr_imm("mmsc-url")); m->mmsc_url = _mms_cfg_getx(x, octstr_imm("mmsc-url"));
@ -211,12 +211,12 @@ int mms_load_mmsbox_settings(mCfg *cfg, gwthread_func_t *mmsc_handler_func)
#ifdef HAVE_LIBSSL #ifdef HAVE_LIBSSL
mms_cfg_get_bool(x, octstr_imm("incoming-port-ssl"), &ssl); mms_cfg_get_bool(x, octstr_imm("incoming-port-ssl"), &ssl);
#endif #endif
if ((tmp = _mms_cfg_getx(x, octstr_imm("max-throughput"))) != NULL) { if ((tmp = mms_cfg_get(x, octstr_imm("max-throughput"))) != NULL) {
if (octstr_parse_double(&m->throughput, tmp, 0) == -1) if (octstr_parse_double(&m->throughput, tmp, 0) == -1)
m->throughput = 0; m->throughput = 0;
octstr_destroy(tmp);
info(0, "Set throughput to %.3f for mmsc id <%s>", info(0, "Set throughput to %.3f for mmsc id <%s>",
m->throughput, octstr_get_cstr(m->id)); m->throughput, octstr_get_cstr(m->id));
octstr_destroy(tmp);
} }
type = _mms_cfg_getx(x, octstr_imm("type")); type = _mms_cfg_getx(x, octstr_imm("type"));
@ -456,6 +456,7 @@ int mms_load_mmsbox_settings(mCfg *cfg, gwthread_func_t *mmsc_handler_func)
gwlist_append(mms_services, m); gwlist_append(mms_services, m);
} }
gwlist_destroy(l, NULL); gwlist_destroy(l, NULL);
octstr_destroy(gdir);
return 0; return 0;
} }

View File

@ -154,8 +154,8 @@ static void start_push(Octstr *rcpt_to, int isphonenum, MmsEnvelope *e, MmsMsg *
static int receive_push_reply(HTTPCaller *caller) static int receive_push_reply(HTTPCaller *caller)
{ {
int http_status; int http_status;
List *reply_headers; List *reply_headers = NULL;
Octstr *final_url, *reply_body; Octstr *final_url = NULL, *reply_body = NULL;
MmsEnvelope *env; MmsEnvelope *env;
@ -211,14 +211,14 @@ static int receive_push_reply(HTTPCaller *caller)
/* Fall through. */ /* Fall through. */
push_failed: push_failed:
octstr_destroy(final_url);
octstr_destroy(reply_body);
http_destroy_headers(reply_headers);
env = update_env_failed(env); env = update_env_failed(env);
push_free_env: push_free_env:
if (env && env != &edummy) if (env && env != &edummy)
settings->qfs->mms_queue_free_env(env); settings->qfs->mms_queue_free_env(env);
octstr_destroy(final_url);
octstr_destroy(reply_body);
http_destroy_headers(reply_headers);
} }
return 0; return 0;