[evolution-data-server] [IMAPx] Prefer existing allocate/deallocate structure functions
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] [IMAPx] Prefer existing allocate/deallocate structure functions
- Date: Wed, 13 Jun 2018 10:08:48 +0000 (UTC)
commit 98dc15a25dbea45c4bb87010ff443703599314c9
Author: Milan Crha <mcrha redhat com>
Date: Wed Jun 13 12:08:09 2018 +0200
[IMAPx] Prefer existing allocate/deallocate structure functions
Using existing functions avoids code duplication and ensures that
there will not me alloc/dealloc function mismatch. The duplicated
code meant a memory leak in this case.
This had been discovered within https://gitlab.gnome.org/GNOME/evolution-data-server/issues/6
src/camel/camel-mime-utils.c | 16 +++++++++++--
src/camel/camel-mime-utils.h | 1 +
src/camel/providers/imapx/camel-imapx-utils.c | 34 ++++++---------------------
src/camel/providers/imapx/camel-imapx-utils.h | 1 -
4 files changed, 22 insertions(+), 30 deletions(-)
---
diff --git a/src/camel/camel-mime-utils.c b/src/camel/camel-mime-utils.c
index 0a68fd230..35d8eef68 100644
--- a/src/camel/camel-mime-utils.c
+++ b/src/camel/camel-mime-utils.c
@@ -3792,6 +3792,19 @@ camel_content_transfer_encoding_decode (const gchar *in)
return NULL;
}
+CamelContentDisposition *
+camel_content_disposition_new (void)
+{
+ CamelContentDisposition *dd;
+
+ dd = g_malloc0 (sizeof (CamelContentDisposition));
+ dd->refcount = 1;
+ dd->disposition = NULL;
+ dd->params = NULL;
+
+ return dd;
+}
+
CamelContentDisposition *
camel_content_disposition_decode (const gchar *in)
{
@@ -3801,8 +3814,7 @@ camel_content_disposition_decode (const gchar *in)
if (in == NULL)
return NULL;
- d = g_malloc (sizeof (*d));
- d->refcount = 1;
+ d = camel_content_disposition_new ();
d->disposition = decode_token (&inptr);
if (d->disposition == NULL) {
w (g_warning ("Empty disposition type"));
diff --git a/src/camel/camel-mime-utils.h b/src/camel/camel-mime-utils.h
index 484020718..f0383a62c 100644
--- a/src/camel/camel-mime-utils.h
+++ b/src/camel/camel-mime-utils.h
@@ -138,6 +138,7 @@ void camel_content_type_dump (CamelContentType *content_type);
/* Content-Disposition header */
GType camel_content_disposition_get_type (void) G_GNUC_CONST;
+CamelContentDisposition *camel_content_disposition_new (void);
CamelContentDisposition *camel_content_disposition_decode (const gchar *in);
CamelContentDisposition *camel_content_disposition_ref (CamelContentDisposition *disposition);
void camel_content_disposition_unref (CamelContentDisposition *disposition);
diff --git a/src/camel/providers/imapx/camel-imapx-utils.c b/src/camel/providers/imapx/camel-imapx-utils.c
index 81c4ef765..dd6878522 100644
--- a/src/camel/providers/imapx/camel-imapx-utils.c
+++ b/src/camel/providers/imapx/camel-imapx-utils.c
@@ -785,26 +785,6 @@ struct _body_fields {
guint32 size;
};*/
-void
-imapx_free_body (struct _CamelMessageContentInfo *cinfo)
-{
- struct _CamelMessageContentInfo *list, *next;
-
- list = cinfo->childs;
- while (list) {
- next = list->next;
- imapx_free_body (list);
- list = next;
- }
-
- if (cinfo->type)
- camel_content_type_unref (cinfo->type);
- g_free (cinfo->id);
- g_free (cinfo->description);
- g_free (cinfo->encoding);
- g_free (cinfo);
-}
-
gboolean
imapx_parse_param_list (CamelIMAPXInputStream *stream,
struct _camel_header_param **plist,
@@ -879,8 +859,8 @@ imapx_parse_ext_optional (CamelIMAPXInputStream *stream,
stream, &token, &len, cancellable, NULL);
switch (tok) {
case '(':
- dinfo = g_malloc0 (sizeof (*dinfo));
- dinfo->refcount = 1;
+ dinfo = camel_content_disposition_new ();
+
/* should be string */
if (!camel_imapx_input_stream_astring (stream, &token, cancellable, &local_error)) {
if (!local_error)
@@ -978,7 +958,7 @@ imapx_parse_body_fields (CamelIMAPXInputStream *stream,
* body_fld_desc SPACE body_fld_enc SPACE
* body_fld_octets */
- cinfo = g_malloc0 (sizeof (*cinfo));
+ cinfo = camel_message_content_info_new ();
/* this should be string not astring */
success = camel_imapx_input_stream_astring (
@@ -1045,7 +1025,7 @@ imapx_parse_body_fields (CamelIMAPXInputStream *stream,
return cinfo;
error:
- imapx_free_body (cinfo);
+ camel_message_content_info_free (cinfo);
return NULL;
}
@@ -1361,7 +1341,7 @@ imapx_parse_body (CamelIMAPXInputStream *stream,
/* body_type_mpart ::= 1*body SPACE media_subtype
[SPACE body_ext_mpart] */
- cinfo = g_malloc0 (sizeof (*cinfo));
+ cinfo = camel_message_content_info_new ();
last = (struct _CamelMessageContentInfo *) &cinfo->childs;
do {
subinfo = imapx_parse_body (stream, cancellable, &local_error);
@@ -1550,7 +1530,7 @@ imapx_parse_body (CamelIMAPXInputStream *stream,
if (local_error != NULL) {
g_propagate_error (error, local_error);
if (cinfo)
- imapx_free_body (cinfo);
+ camel_message_content_info_free (cinfo);
if (dinfo)
camel_content_disposition_unref (dinfo);
return NULL;
@@ -1707,7 +1687,7 @@ imapx_free_fetch (struct _fetch_info *finfo)
if (finfo->header)
g_bytes_unref (finfo->header);
if (finfo->cinfo)
- imapx_free_body (finfo->cinfo);
+ camel_message_content_info_free (finfo->cinfo);
camel_named_flags_free (finfo->user_flags);
g_clear_object (&finfo->minfo);
g_free (finfo->date);
diff --git a/src/camel/providers/imapx/camel-imapx-utils.h b/src/camel/providers/imapx/camel-imapx-utils.h
index 9f1eaa702..89c301934 100644
--- a/src/camel/providers/imapx/camel-imapx-utils.h
+++ b/src/camel/providers/imapx/camel-imapx-utils.h
@@ -233,7 +233,6 @@ CamelMessageContentInfo *
gchar * imapx_parse_section (CamelIMAPXInputStream *stream,
GCancellable *cancellable,
GError **error);
-void imapx_free_body (struct _CamelMessageContentInfo *cinfo);
/* ********************************************************************** */
/* all the possible stuff we might get from a fetch request */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]