Skip to content

Commit

Permalink
global: start relying on [io]_stream_unref(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) {
	- 	i_stream_unref(&E);
	- }
	+ i_stream_unref(&E);

	@@
	expression E;
	@@

	- if (E != NULL) {
	- 	o_stream_unref(&E);
	- }
	+ o_stream_unref(&E);
  • Loading branch information
stephanbosch committed Dec 15, 2017
1 parent 45cfd19 commit dbc3f2f
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 21 deletions.
7 changes: 2 additions & 5 deletions src/lib-managesieve/managesieve-parser.c
Expand Up @@ -70,8 +70,7 @@ managesieve_parser_create(struct istream *input, size_t max_line_size)

void managesieve_parser_destroy(struct managesieve_parser **parser)
{
if ((*parser)->str_stream != NULL)
i_stream_unref(&(*parser)->str_stream);
i_stream_unref(&(*parser)->str_stream);

pool_unref(&(*parser)->pool);
i_free(*parser);
Expand Down Expand Up @@ -99,9 +98,7 @@ void managesieve_parser_reset(struct managesieve_parser *parser)
parser->literal_skip_crlf = FALSE;
parser->eol = FALSE;

if ( parser->str_stream != NULL )
i_stream_unref(&parser->str_stream);
parser->str_stream = NULL;
i_stream_unref(&parser->str_stream);
}

const char *managesieve_parser_get_error
Expand Down
4 changes: 1 addition & 3 deletions src/lib-sieve-tool/mail-raw.c
Expand Up @@ -220,9 +220,7 @@ struct mail_raw *mail_raw_open_file
}

mailr = mail_raw_create(ruser, input, path, sender, mtime);

if ( input != NULL )
i_stream_unref(&input);
i_stream_unref(&input);

return mailr;
}
Expand Down
3 changes: 1 addition & 2 deletions src/lib-sieve/sieve-script.c
Expand Up @@ -147,8 +147,7 @@ void sieve_script_unref(struct sieve_script **_script)
if ( --script->refcount != 0 )
return;

if ( script->stream != NULL )
i_stream_unref(&script->stream);
i_stream_unref(&script->stream);

if ( script->v.destroy != NULL )
script->v.destroy(script);
Expand Down
3 changes: 1 addition & 2 deletions src/lib-sieve/storage/ldap/sieve-ldap-db.c
Expand Up @@ -1339,8 +1339,7 @@ sieve_ldap_read_script_callback(struct ldap_connection *conn,
} else {
sieve_storage_sys_error(storage, "db: "
"Search returned more than one entry for Sieve script DN");
if (srequest->result != NULL)
i_stream_unref(&srequest->result);
i_stream_unref(&srequest->result);
}

} else {
Expand Down
11 changes: 2 additions & 9 deletions src/lib-sieve/util/edit-mail.c
Expand Up @@ -350,10 +350,7 @@ void edit_mail_reset(struct edit_mail *edmail)
struct _header_index *header_idx;
struct _header_field_index *field_idx;

if ( edmail->stream != NULL ) {
i_stream_unref(&edmail->stream);
edmail->stream = NULL;
}
i_stream_unref(&edmail->stream);

field_idx = edmail->header_fields_head;
while ( field_idx != NULL ) {
Expand Down Expand Up @@ -387,11 +384,7 @@ void edit_mail_unwrap(struct edit_mail **edmail)
return;

edit_mail_reset(*edmail);

if ( (*edmail)->wrapped_stream != NULL ) {
i_stream_unref(&(*edmail)->wrapped_stream);
(*edmail)->wrapped_stream = NULL;
}
i_stream_unref(&(*edmail)->wrapped_stream);

parent = (*edmail)->parent;

Expand Down

0 comments on commit dbc3f2f

Please sign in to comment.