From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 489506DE09CD for ; Fri, 20 Mar 2020 14:58:38 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.387 X-Spam-Level: X-Spam-Status: No, score=0.387 tagged_above=-999 required=5 tests=[AWL=-0.265, SPF_NEUTRAL=0.652] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id q4KmCze-PI1W for ; Fri, 20 Mar 2020 14:58:36 -0700 (PDT) Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) by arlo.cworth.org (Postfix) with ESMTP id 484986DE0948 for ; Fri, 20 Mar 2020 14:58:35 -0700 (PDT) Received: from guru.guru-group.fi (localhost [IPv6:::1]) by guru.guru-group.fi (Postfix) with ESMTP id 31D041000B0; Fri, 20 Mar 2020 23:58:30 +0200 (EET) From: Tomi Ollila To: Daniel Kahn Gillmor , Notmuch Mail Subject: Re: [PATCH 2/2] mime-node: Clean up unwrapped MIME parts correctly. In-Reply-To: <20200319054145.803668-3-dkg@fifthhorseman.net> References: <20200319054145.803668-1-dkg@fifthhorseman.net> <20200319054145.803668-3-dkg@fifthhorseman.net> User-Agent: Notmuch/0.28.3+84~g41389bb (https://notmuchmail.org) Emacs/25.2.1 (x86_64-unknown-linux-gnu) X-Face: HhBM'cA~ MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Mar 2020 21:58:38 -0000 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 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