Skip to content

Commit

Permalink
global: start relying on buffer_free(NULL) being a no-op
Browse files Browse the repository at this point in the history
Cleanup performed with the following semantic patch:

	@@
	expression E;
	@@

	- if (E != NULL) {
	- 	buffer_free(&E);
	- }
	+ buffer_free(&E);
  • Loading branch information
Josef 'Jeff' Sipek committed Sep 20, 2017
1 parent 1a6ff0b commit 6307d76
Show file tree
Hide file tree
Showing 26 changed files with 34 additions and 66 deletions.
3 changes: 1 addition & 2 deletions src/lib-compression/istream-lz4.c
Expand Up @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions src/lib-dcrypt/istream-decrypt.c
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions src/lib-fts/fts-tokenizer.c
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/lib-imap-urlauth/imap-urlauth-connection.c
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/lib-index/mail-cache-transaction.c
Expand Up @@ -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))
Expand Down
3 changes: 1 addition & 2 deletions src/lib-index/mail-cache.c
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/lib-index/mail-index-sync-update.c
Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions src/lib-index/mail-index-transaction-update.c
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/lib-index/mail-index-transaction-view.c
Expand Up @@ -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);
Expand Down
13 changes: 5 additions & 8 deletions src/lib-index/mail-transaction-log-file.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/lib-mail/istream-attachment-extractor.c
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/lib-mail/istream-qp-decoder.c
Expand Up @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions src/lib-mail/istream-qp-encoder.c
Expand Up @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions src/lib-mail/message-header-decode.c
Expand Up @@ -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 {
Expand Down
9 changes: 3 additions & 6 deletions src/lib-mail/test-istream-attachment.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions src/lib-ssl-iostream/ostream-openssl.c
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/lib-storage/index/imapc/imapc-mail.c
Expand Up @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions src/lib-storage/index/imapc/imapc-storage.c
Expand Up @@ -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;
}

Expand Down
3 changes: 1 addition & 2 deletions src/lib-storage/index/index-mail.c
Expand Up @@ -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))
Expand Down
3 changes: 1 addition & 2 deletions src/lib-test/test-ostream.c
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions src/lib/iostream-rawlog.c
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/lib/iostream-temp.c
Expand Up @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions src/lib/istream-seekable.c
Expand Up @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions src/lmtp/client.c
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions src/plugins/fts/fts-build-mail.c
Expand Up @@ -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;
}

Expand Down
3 changes: 1 addition & 2 deletions src/plugins/fts/fts-parser.c
Expand Up @@ -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
Expand Down

0 comments on commit 6307d76

Please sign in to comment.