From: Timo Sirainen Date: Thu, 18 May 2017 16:40:04 +0000 (+0300) Subject: lib-imap: imap_parser_unref() should always set parser=NULL X-Git-Tag: 2.2.30.rc1~23 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5e1694a575134fa95f530ea6da7c6b7fdc7b71e0;p=thirdparty%2Fdovecot%2Fcore.git lib-imap: imap_parser_unref() should always set parser=NULL Not just when the last reference is cleared. This is how *_unref()s should work everywhere in Dovecot. This fixes a bug in lib-imap-client where a parser could have been accessed after it was already freed. --- diff --git a/src/lib-imap/imap-parser.c b/src/lib-imap/imap-parser.c index 14290e8862..9df169e82d 100644 --- a/src/lib-imap/imap-parser.c +++ b/src/lib-imap/imap-parser.c @@ -91,16 +91,18 @@ void imap_parser_ref(struct imap_parser *parser) parser->refcount++; } -void imap_parser_unref(struct imap_parser **parser) +void imap_parser_unref(struct imap_parser **_parser) { - i_assert((*parser)->refcount > 0); + struct imap_parser *parser = *_parser; - if (--(*parser)->refcount > 0) + *_parser = NULL; + + i_assert(parser->refcount > 0); + if (--parser->refcount > 0) return; - pool_unref(&(*parser)->pool); - i_free(*parser); - *parser = NULL; + pool_unref(&parser->pool); + i_free(parser); } void imap_parser_reset(struct imap_parser *parser)