From: Josef 'Jeff' Sipek Date: Tue, 19 Sep 2017 10:33:06 +0000 (+0300) Subject: global: start relying on buffer_free(NULL) being a no-op X-Git-Tag: 2.3.0.rc1~976 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6307d76096764e66bddc63d4a3e5a1aa19cc528f;p=thirdparty%2Fdovecot%2Fcore.git global: start relying on buffer_free(NULL) being a no-op Cleanup performed with the following semantic patch: @@ expression E; @@ - if (E != NULL) { - buffer_free(&E); - } + buffer_free(&E); --- diff --git a/src/lib-compression/istream-lz4.c b/src/lib-compression/istream-lz4.c index 89e5609f86..d6a28c7128 100644 --- a/src/lib-compression/istream-lz4.c +++ b/src/lib-compression/istream-lz4.c @@ -29,8 +29,7 @@ static void i_stream_lz4_close(struct iostream_private *stream, { struct lz4_istream *zstream = (struct lz4_istream *)stream; - if (zstream->chunk_buf != NULL) - buffer_free(&zstream->chunk_buf); + buffer_free(&zstream->chunk_buf); if (close_parent) i_stream_close(zstream->istream.parent); } diff --git a/src/lib-dcrypt/istream-decrypt.c b/src/lib-dcrypt/istream-decrypt.c index 70051ddbd5..4534f9f4ac 100644 --- a/src/lib-dcrypt/istream-decrypt.c +++ b/src/lib-dcrypt/istream-decrypt.c @@ -836,8 +836,7 @@ void i_stream_decrypt_destroy(struct iostream_private *stream) struct decrypt_istream *dstream = (struct decrypt_istream *)stream; - if (dstream->buf != NULL) - buffer_free(&dstream->buf); + buffer_free(&dstream->buf); if (dstream->iv != NULL) i_free_and_null(dstream->iv); if (dstream->ctx_sym != NULL) diff --git a/src/lib-fts/fts-tokenizer.c b/src/lib-fts/fts-tokenizer.c index 6fef5cadaf..75035c8dda 100644 --- a/src/lib-fts/fts-tokenizer.c +++ b/src/lib-fts/fts-tokenizer.c @@ -121,8 +121,7 @@ void fts_tokenizer_unref(struct fts_tokenizer **_tok) if (--tok->refcount > 0) return; - if (tok->parent_input != NULL) - buffer_free(&tok->parent_input); + buffer_free(&tok->parent_input); if (tok->parent != NULL) fts_tokenizer_unref(&tok->parent); tok->v->destroy(tok); diff --git a/src/lib-imap-urlauth/imap-urlauth-connection.c b/src/lib-imap-urlauth/imap-urlauth-connection.c index 9af54a4cf4..396e8b79ec 100644 --- a/src/lib-imap-urlauth/imap-urlauth-connection.c +++ b/src/lib-imap-urlauth/imap-urlauth-connection.c @@ -973,8 +973,7 @@ static void imap_urlauth_connection_disconnect conn->literal_fd = -1; } - if (conn->literal_buf != NULL) - buffer_free(&conn->literal_buf); + buffer_free(&conn->literal_buf); timeout_remove(&conn->to_reconnect); timeout_remove(&conn->to_idle); imap_urlauth_stop_response_timeout(conn); diff --git a/src/lib-index/mail-cache-transaction.c b/src/lib-index/mail-cache-transaction.c index 0db357b546..2c8b36af00 100644 --- a/src/lib-index/mail-cache-transaction.c +++ b/src/lib-index/mail-cache-transaction.c @@ -156,8 +156,7 @@ void mail_cache_transaction_rollback(struct mail_cache_transaction_ctx **_ctx) ctx->view->trans_seq1 = ctx->view->trans_seq2 = 0; mail_index_view_close(&ctx->view->trans_view); - if (ctx->cache_data != NULL) - buffer_free(&ctx->cache_data); + buffer_free(&ctx->cache_data); if (array_is_created(&ctx->cache_data_seq)) array_free(&ctx->cache_data_seq); if (array_is_created(&ctx->cache_data_wanted_seqs)) diff --git a/src/lib-index/mail-cache.c b/src/lib-index/mail-cache.c index 96e1e17fb3..ba2d1ca087 100644 --- a/src/lib-index/mail-cache.c +++ b/src/lib-index/mail-cache.c @@ -587,8 +587,7 @@ void mail_cache_free(struct mail_cache **_cache) mail_index_unregister_expunge_handler(cache->index, cache->ext_id); mail_cache_file_close(cache); - if (cache->read_buf != NULL) - buffer_free(&cache->read_buf); + buffer_free(&cache->read_buf); hash_table_destroy(&cache->field_name_hash); pool_unref(&cache->field_pool); i_free(cache->field_file_map); diff --git a/src/lib-index/mail-index-sync-update.c b/src/lib-index/mail-index-sync-update.c index 059da27cf9..ba0ce292c5 100644 --- a/src/lib-index/mail-index-sync-update.c +++ b/src/lib-index/mail-index-sync-update.c @@ -839,8 +839,7 @@ void mail_index_sync_map_deinit(struct mail_index_sync_map_ctx *sync_map_ctx) { i_assert(sync_map_ctx->modseq_ctx == NULL); - if (sync_map_ctx->unknown_extensions != NULL) - buffer_free(&sync_map_ctx->unknown_extensions); + buffer_free(&sync_map_ctx->unknown_extensions); if (sync_map_ctx->expunge_handlers_used) mail_index_sync_deinit_expunge_handlers(sync_map_ctx); mail_index_sync_deinit_handlers(sync_map_ctx); diff --git a/src/lib-index/mail-index-transaction-update.c b/src/lib-index/mail-index-transaction-update.c index 9c89cf4ffc..ab8de2bbc3 100644 --- a/src/lib-index/mail-index-transaction-update.c +++ b/src/lib-index/mail-index-transaction-update.c @@ -76,10 +76,8 @@ void mail_index_transaction_reset_v(struct mail_index_transaction *t) array_free(&t->ext_reset_ids); if (array_is_created(&t->ext_reset_atomic)) array_free(&t->ext_reset_atomic); - if (t->attribute_updates != NULL) - buffer_free(&t->attribute_updates); - if (t->attribute_updates_suffix != NULL) - buffer_free(&t->attribute_updates_suffix); + buffer_free(&t->attribute_updates); + buffer_free(&t->attribute_updates_suffix); t->first_new_seq = mail_index_view_get_messages_count(t->view)+1; t->last_new_seq = 0; diff --git a/src/lib-index/mail-index-transaction-view.c b/src/lib-index/mail-index-transaction-view.c index 349f581273..131b768ed3 100644 --- a/src/lib-index/mail-index-transaction-view.c +++ b/src/lib-index/mail-index-transaction-view.c @@ -35,8 +35,7 @@ static void tview_close(struct mail_index_view *view) if (tview->lookup_map != NULL) mail_index_unmap(&tview->lookup_map); - if (tview->lookup_return_data != NULL) - buffer_free(&tview->lookup_return_data); + buffer_free(&tview->lookup_return_data); if (array_is_created(&tview->all_recs)) { recs = array_get_modifiable(&tview->all_recs, &count); diff --git a/src/lib-index/mail-transaction-log-file.c b/src/lib-index/mail-transaction-log-file.c index 1dddff9208..4fef9dc745 100644 --- a/src/lib-index/mail-transaction-log-file.c +++ b/src/lib-index/mail-transaction-log-file.c @@ -114,8 +114,7 @@ void mail_transaction_log_file_free(struct mail_transaction_log_file **_file) if (file == file->log->head) file->log->head = NULL; - if (file->buffer != NULL) - buffer_free(&file->buffer); + buffer_free(&file->buffer); if (file->mmap_base != NULL) { if (munmap(file->mmap_base, file->mmap_size) < 0) @@ -957,8 +956,7 @@ int mail_transaction_log_file_open(struct mail_transaction_log_file *file, } /* ESTALE - try again */ - if (file->buffer != NULL) - buffer_free(&file->buffer); + buffer_free(&file->buffer); } mail_transaction_log_file_add_to_list(file); @@ -1733,10 +1731,9 @@ static int mail_transaction_log_file_mmap(struct mail_transaction_log_file *file, const char **reason_r) { - if (file->buffer != NULL) { - /* in case we just switched to mmaping */ - buffer_free(&file->buffer); - } + /* we may have switched to mmaping */ + buffer_free(&file->buffer); + file->mmap_size = file->last_size; file->mmap_base = mmap(NULL, file->mmap_size, PROT_READ, MAP_SHARED, file->fd, 0); diff --git a/src/lib-mail/istream-attachment-extractor.c b/src/lib-mail/istream-attachment-extractor.c index b9ba462b63..b1b4026e5e 100644 --- a/src/lib-mail/istream-attachment-extractor.c +++ b/src/lib-mail/istream-attachment-extractor.c @@ -538,8 +538,7 @@ static void astream_part_reset(struct attachment_istream *astream) i_free_and_null(part->content_type); i_free_and_null(part->content_disposition); - if (part->part_buf != NULL) - buffer_free(&part->part_buf); + buffer_free(&part->part_buf); i_zero(part); part->temp_fd = -1; diff --git a/src/lib-mail/istream-qp-decoder.c b/src/lib-mail/istream-qp-decoder.c index e8361fe3bf..cc86654ee7 100644 --- a/src/lib-mail/istream-qp-decoder.c +++ b/src/lib-mail/istream-qp-decoder.c @@ -21,8 +21,7 @@ static void i_stream_qp_decoder_close(struct iostream_private *stream, if (bstream->qp != NULL) qp_decoder_deinit(&bstream->qp); - if (bstream->buf != NULL) - buffer_free(&bstream->buf); + buffer_free(&bstream->buf); if (close_parent) i_stream_close(bstream->istream.parent); } diff --git a/src/lib-mail/istream-qp-encoder.c b/src/lib-mail/istream-qp-encoder.c index d68ed12b44..19eb0a765d 100644 --- a/src/lib-mail/istream-qp-encoder.c +++ b/src/lib-mail/istream-qp-encoder.c @@ -21,8 +21,7 @@ static void i_stream_qp_encoder_close(struct iostream_private *stream, if (bstream->qp != NULL) qp_encoder_deinit(&bstream->qp); - if (bstream->buf != NULL) - buffer_free(&bstream->buf); + buffer_free(&bstream->buf); if (close_parent) i_stream_close(bstream->istream.parent); } diff --git a/src/lib-mail/message-header-decode.c b/src/lib-mail/message-header-decode.c index 36d5234031..d13b4e7bef 100644 --- a/src/lib-mail/message-header-decode.c +++ b/src/lib-mail/message-header-decode.c @@ -132,8 +132,7 @@ void message_header_decode(const unsigned char *data, size_t size, (void)callback(data + start_pos, size - start_pos, NULL, context); } - if (decodebuf != NULL) - buffer_free(&decodebuf); + buffer_free(&decodebuf); } struct decode_utf8_context { diff --git a/src/lib-mail/test-istream-attachment.c b/src/lib-mail/test-istream-attachment.c index 9089046ab6..d97bcf5f5b 100644 --- a/src/lib-mail/test-istream-attachment.c +++ b/src/lib-mail/test-istream-attachment.c @@ -313,8 +313,7 @@ static int test_input_stream(struct istream *file_input) } buffer_free(&base_buf); - if (attachment_data != NULL) - buffer_free(&attachment_data); + buffer_free(&attachment_data); if (array_is_created(&attachments)) array_free(&attachments); return ret; @@ -357,8 +356,7 @@ static void test_istream_attachment(void) i_stream_unref(&input); i_stream_unref(&datainput); - if (attachment_data != NULL) - buffer_free(&attachment_data); + buffer_free(&attachment_data); if (array_is_created(&attachments)) array_free(&attachments); test_end(); @@ -406,8 +404,7 @@ static bool test_istream_attachment_extractor_one(const char *body, int err_type memcmp(data, body + attachment_data->used, size) == 0; cleanup: - if (attachment_data != NULL) - buffer_free(&attachment_data); + buffer_free(&attachment_data); if (array_is_created(&attachments)) array_free(&attachments); diff --git a/src/lib-ssl-iostream/ostream-openssl.c b/src/lib-ssl-iostream/ostream-openssl.c index 20b47455f4..b000286633 100644 --- a/src/lib-ssl-iostream/ostream-openssl.c +++ b/src/lib-ssl-iostream/ostream-openssl.c @@ -26,8 +26,7 @@ static void o_stream_ssl_destroy(struct iostream_private *stream) sstream->ssl_io->ssl_output = NULL; ssl_iostream_unref(&sstream->ssl_io); - if (sstream->buffer != NULL) - buffer_free(&sstream->buffer); + buffer_free(&sstream->buffer); } static size_t diff --git a/src/lib-storage/index/imapc/imapc-mail.c b/src/lib-storage/index/imapc/imapc-mail.c index d203f17d82..7059f2e8d5 100644 --- a/src/lib-storage/index/imapc/imapc-mail.c +++ b/src/lib-storage/index/imapc/imapc-mail.c @@ -454,8 +454,7 @@ static void imapc_mail_close(struct mail *_mail) i_error("close(imapc mail) failed: %m"); mail->fd = -1; } - if (mail->body != NULL) - buffer_free(&mail->body); + buffer_free(&mail->body); mail->header_fetched = FALSE; mail->body_fetched = FALSE; diff --git a/src/lib-storage/index/imapc/imapc-storage.c b/src/lib-storage/index/imapc/imapc-storage.c index f09fd0dea4..d7332f657a 100644 --- a/src/lib-storage/index/imapc/imapc-storage.c +++ b/src/lib-storage/index/imapc/imapc-storage.c @@ -768,8 +768,7 @@ void imapc_mail_cache_free(struct imapc_mail_cache *cache) i_error("close(imapc cached mail) failed: %m"); cache->fd = -1; } - if (cache->buf != NULL) - buffer_free(&cache->buf); + buffer_free(&cache->buf); cache->uid = 0; } diff --git a/src/lib-storage/index/index-mail.c b/src/lib-storage/index/index-mail.c index 21e9da7f37..a6cadf7c83 100644 --- a/src/lib-storage/index/index-mail.c +++ b/src/lib-storage/index/index-mail.c @@ -2047,8 +2047,7 @@ void index_mail_free(struct mail *_mail) i_assert(_mail->transaction->mail_ref_count > 0); _mail->transaction->mail_ref_count--; - if (mail->header_data != NULL) - buffer_free(&mail->header_data); + buffer_free(&mail->header_data); if (array_is_created(&mail->header_lines)) array_free(&mail->header_lines); if (array_is_created(&mail->header_match)) diff --git a/src/lib-test/test-ostream.c b/src/lib-test/test-ostream.c index 674bba9c92..01e9fb75a2 100644 --- a/src/lib-test/test-ostream.c +++ b/src/lib-test/test-ostream.c @@ -19,8 +19,7 @@ static void o_stream_test_destroy(struct iostream_private *stream) struct test_ostream *tstream = (struct test_ostream *)stream; timeout_remove(&tstream->to); - if (tstream->internal_buf != NULL) - buffer_free(&tstream->internal_buf); + buffer_free(&tstream->internal_buf); } static int o_stream_test_flush(struct ostream_private *stream) diff --git a/src/lib/iostream-rawlog.c b/src/lib/iostream-rawlog.c index 7d84d5bdd6..7f082b1c39 100644 --- a/src/lib/iostream-rawlog.c +++ b/src/lib/iostream-rawlog.c @@ -136,8 +136,7 @@ void iostream_rawlog_write(struct rawlog_iostream *rstream, void iostream_rawlog_close(struct rawlog_iostream *rstream) { o_stream_unref(&rstream->rawlog_output); - if (rstream->buffer != NULL) - buffer_free(&rstream->buffer); + buffer_free(&rstream->buffer); } static void diff --git a/src/lib/iostream-temp.c b/src/lib/iostream-temp.c index 1e63d97b57..1aa1e90942 100644 --- a/src/lib/iostream-temp.c +++ b/src/lib/iostream-temp.c @@ -40,8 +40,7 @@ o_stream_temp_close(struct iostream_private *stream, struct temp_ostream *tstream = (struct temp_ostream *)stream; i_close_fd(&tstream->fd); - if (tstream->buf != NULL) - buffer_free(&tstream->buf); + buffer_free(&tstream->buf); i_free(tstream->temp_path_prefix); i_free(tstream->name); } diff --git a/src/lib/istream-seekable.c b/src/lib/istream-seekable.c index a8f304abab..ccdd33a5cb 100644 --- a/src/lib/istream-seekable.c +++ b/src/lib/istream-seekable.c @@ -54,8 +54,7 @@ static void i_stream_seekable_destroy(struct iostream_private *stream) { struct seekable_istream *sstream = (struct seekable_istream *)stream; - if (sstream->membuf != NULL) - buffer_free(&sstream->membuf); + buffer_free(&sstream->membuf); i_stream_unref(&sstream->fd_input); unref_streams(sstream); diff --git a/src/lmtp/client.c b/src/lmtp/client.c index 1d9dc3511c..5a47bb4d1f 100644 --- a/src/lmtp/client.c +++ b/src/lmtp/client.c @@ -379,8 +379,7 @@ void client_state_reset(struct client *client, const char *state_name) mailbox_free(&raw_box); } - if (client->state.mail_data != NULL) - buffer_free(&client->state.mail_data); + buffer_free(&client->state.mail_data); o_stream_unref(&client->state.mail_data_output); if (client->state.mail_data_fd != -1) { if (close(client->state.mail_data_fd) < 0) diff --git a/src/plugins/fts/fts-build-mail.c b/src/plugins/fts/fts-build-mail.c index 3be7266e25..0766c67d29 100644 --- a/src/plugins/fts/fts-build-mail.c +++ b/src/plugins/fts/fts-build-mail.c @@ -578,10 +578,8 @@ fts_build_mail_real(struct fts_backend_update_context *update_ctx, message_decoder_deinit(&decoder); i_free(ctx.content_type); i_free(ctx.content_disposition); - if (ctx.word_buf != NULL) - buffer_free(&ctx.word_buf); - if (ctx.pending_input != NULL) - buffer_free(&ctx.pending_input); + buffer_free(&ctx.word_buf); + buffer_free(&ctx.pending_input); return ret < 0 ? -1 : 1; } diff --git a/src/plugins/fts/fts-parser.c b/src/plugins/fts/fts-parser.c index 1921112855..59b20b50ae 100644 --- a/src/plugins/fts/fts-parser.c +++ b/src/plugins/fts/fts-parser.c @@ -98,8 +98,7 @@ int fts_parser_deinit(struct fts_parser **_parser) *_parser = NULL; - if (parser->utf8_output != NULL) - buffer_free(&parser->utf8_output); + buffer_free(&parser->utf8_output); if (parser->v.deinit != NULL) ret = parser->v.deinit(parser); else