unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Tomi Ollila <tomi.ollila@iki.fi>
To: Daniel Kahn Gillmor <dkg@fifthhorseman.net>,
	Notmuch Mail <notmuch@notmuchmail.org>
Subject: Re: [PATCH 2/2] mime-node: Clean up unwrapped MIME parts correctly.
Date: Fri, 20 Mar 2020 23:58:29 +0200	[thread overview]
Message-ID: <m2bloqzo1m.fsf@guru.guru-group.fi> (raw)
In-Reply-To: <20200319054145.803668-3-dkg@fifthhorseman.net>

On Thu, Mar 19 2020, Daniel Kahn Gillmor wrote:

> Avoid a memory leak in the notmuch command line.
>
> gmime_multipart_encrypted_decrypt returns a GMimeObject marked by
> GMime as "transfer full", so we are supposed to clean up after it.
>
> When parsing a message, notmuch would leak one GMimeObject part per
> multipart/encrypted MIME layer.  We clean it up by analogy with
> cleaning up the signature list associated with a MIME node.
>
> Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>

Looks good to me.

Tomi

> ---
>  mime-node.c | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
>
> diff --git a/mime-node.c b/mime-node.c
> index 2a823dfd..ff6805bf 100644
> --- a/mime-node.c
> +++ b/mime-node.c
> @@ -192,6 +192,26 @@ set_signature_list_destructor (mime_node_t *node)
>      }
>  }
>  
> +/* Unwrapped MIME part destructor */
> +static int
> +_unwrapped_child_free (GMimeObject **proxy)
> +{
> +    g_object_unref (*proxy);
> +    return 0;
> +}
> +
> +/* Set up unwrapped MIME part destructor */
> +static void
> +set_unwrapped_child_destructor (mime_node_t *node)
> +{
> +    GMimeObject **proxy = talloc (node, GMimeObject *);
> +
> +    if (proxy) {
> +	*proxy = node->unwrapped_child;
> +	talloc_set_destructor (proxy, _unwrapped_child_free);
> +    }
> +}
> +
>  /* Verify a signed mime node */
>  static void
>  node_verify (mime_node_t *node, GMimeObject *part)
> @@ -238,6 +258,8 @@ node_decrypt_and_verify (mime_node_t *node, GMimeObject *part)
>  							 node->ctx->crypto->decrypt,
>  							 message,
>  							 encrypteddata, &decrypt_result, &err);
> +	if (node->unwrapped_child)
> +	    set_unwrapped_child_destructor (node);
>      }
>      if (! node->unwrapped_child) {
>  	fprintf (stderr, "Failed to decrypt part: %s\n",
> -- 
> 2.25.1

      reply	other threads:[~2020-03-20 21:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-19  5:41 Minor cleanup to mime-node.c Daniel Kahn Gillmor
2020-03-19  5:41 ` [PATCH 1/2] mime-node: rename decrypted_child to unwrapped_child Daniel Kahn Gillmor
2020-03-23  1:38   ` David Bremner
2020-03-19  5:41 ` [PATCH 2/2] mime-node: Clean up unwrapped MIME parts correctly Daniel Kahn Gillmor
2020-03-20 21:58   ` Tomi Ollila [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2bloqzo1m.fsf@guru.guru-group.fi \
    --to=tomi.ollila@iki.fi \
    --cc=dkg@fifthhorseman.net \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).