Skip to content

Commit

Permalink
lazy-expunge: Contexts are now required or checked
Browse files Browse the repository at this point in the history
Satisfied static analyzers
  • Loading branch information
cmouse authored and mrannanj committed Feb 20, 2018
1 parent 18e78d3 commit fc4557f
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/plugins/lazy-expunge/lazy-expunge-plugin.c
Expand Up @@ -20,6 +20,8 @@

#define LAZY_EXPUNGE_CONTEXT(obj) \
MODULE_CONTEXT(obj, lazy_expunge_mail_storage_module)
#define LAZY_EXPUNGE_CONTEXT_REQUIRE(obj) \
MODULE_CONTEXT_REQUIRE(obj, lazy_expunge_mail_storage_module)
#define LAZY_EXPUNGE_LIST_CONTEXT(obj) \
MODULE_CONTEXT(obj, lazy_expunge_mailbox_list_module)
#define LAZY_EXPUNGE_USER_CONTEXT(obj) \
Expand Down Expand Up @@ -179,7 +181,7 @@ lazy_expunge_count_in_transaction(struct lazy_expunge_transaction *lt,
static int lazy_expunge_mail_is_last_instance(struct mail *_mail)
{
struct lazy_expunge_transaction *lt =
LAZY_EXPUNGE_CONTEXT(_mail->transaction);
LAZY_EXPUNGE_CONTEXT_REQUIRE(_mail->transaction);
const char *value, *errstr;
unsigned long refcount;
enum mail_error error;
Expand Down Expand Up @@ -239,7 +241,7 @@ static bool lazy_expunge_is_internal_mailbox(struct mailbox *box)
struct lazy_expunge_mailbox_list *llist =
LAZY_EXPUNGE_LIST_CONTEXT(box->list);

if (llist == NULL) {
if (luser == NULL || llist == NULL) {
/* lazy_expunge not enabled at all */
return FALSE;
}
Expand Down Expand Up @@ -284,13 +286,16 @@ static void lazy_expunge_mail_expunge(struct mail *_mail)
struct mail_private *mail = (struct mail_private *)_mail;
struct lazy_expunge_mail *mmail = LAZY_EXPUNGE_MAIL_CONTEXT(mail);
struct lazy_expunge_transaction *lt =
LAZY_EXPUNGE_CONTEXT(_mail->transaction);
LAZY_EXPUNGE_CONTEXT_REQUIRE(_mail->transaction);
struct mail *real_mail;
struct mail_save_context *save_ctx;
const char *error;
bool moving = mmail->moving;
int ret;

i_assert(luser != NULL);
i_assert(mmail != NULL);

if (lt->delayed_error != MAIL_ERROR_NONE)
return;
if (mmail->recursing) {
Expand Down Expand Up @@ -365,7 +370,7 @@ static int lazy_expunge_copy(struct mail_save_context *ctx, struct mail *_mail)
{
struct mail_private *mail = (struct mail_private *)_mail;
union mailbox_module_context *mbox =
LAZY_EXPUNGE_CONTEXT(ctx->transaction->box);
LAZY_EXPUNGE_CONTEXT_REQUIRE(ctx->transaction->box);
struct lazy_expunge_mail *mmail = LAZY_EXPUNGE_MAIL_CONTEXT(mail);

if (mmail != NULL)
Expand All @@ -380,10 +385,12 @@ lazy_expunge_transaction_begin(struct mailbox *box,
{
struct lazy_expunge_mail_user *luser =
LAZY_EXPUNGE_USER_CONTEXT(box->list->ns->user);
union mailbox_module_context *mbox = LAZY_EXPUNGE_CONTEXT(box);
union mailbox_module_context *mbox = LAZY_EXPUNGE_CONTEXT_REQUIRE(box);
struct mailbox_transaction_context *t;
struct lazy_expunge_transaction *lt;

i_assert(luser != NULL);

t = mbox->super.transaction_begin(box, flags, reason);
lt = i_new(struct lazy_expunge_transaction, 1);
lt->copy_only_last_instance = luser->copy_only_last_instance;
Expand All @@ -410,8 +417,8 @@ static int
lazy_expunge_transaction_commit(struct mailbox_transaction_context *ctx,
struct mail_transaction_commit_changes *changes_r)
{
union mailbox_module_context *mbox = LAZY_EXPUNGE_CONTEXT(ctx->box);
struct lazy_expunge_transaction *lt = LAZY_EXPUNGE_CONTEXT(ctx);
union mailbox_module_context *mbox = LAZY_EXPUNGE_CONTEXT_REQUIRE(ctx->box);
struct lazy_expunge_transaction *lt = LAZY_EXPUNGE_CONTEXT_REQUIRE(ctx);
int ret;

if (lt->dest_trans != NULL && lt->delayed_error == MAIL_ERROR_NONE) {
Expand Down Expand Up @@ -441,8 +448,8 @@ lazy_expunge_transaction_commit(struct mailbox_transaction_context *ctx,
static void
lazy_expunge_transaction_rollback(struct mailbox_transaction_context *ctx)
{
union mailbox_module_context *mbox = LAZY_EXPUNGE_CONTEXT(ctx->box);
struct lazy_expunge_transaction *lt = LAZY_EXPUNGE_CONTEXT(ctx);
union mailbox_module_context *mbox = LAZY_EXPUNGE_CONTEXT_REQUIRE(ctx->box);
struct lazy_expunge_transaction *lt = LAZY_EXPUNGE_CONTEXT_REQUIRE(ctx);

mbox->super.transaction_rollback(ctx);
lazy_expunge_transaction_free(lt);
Expand Down Expand Up @@ -470,12 +477,14 @@ static void lazy_expunge_mail_allocated(struct mail *_mail)
static int
lazy_expunge_mailbox_rename(struct mailbox *src, struct mailbox *dest)
{
union mailbox_module_context *lbox = LAZY_EXPUNGE_CONTEXT(src);
union mailbox_module_context *lbox = LAZY_EXPUNGE_CONTEXT_REQUIRE(src);
struct lazy_expunge_mailbox_list *src_llist =
LAZY_EXPUNGE_LIST_CONTEXT(src->list);
struct lazy_expunge_mailbox_list *dest_llist =
LAZY_EXPUNGE_LIST_CONTEXT(dest->list);

i_assert(src_llist != NULL && dest_llist != NULL);

if (!src_llist->allow_rename &&
(src_llist->internal_namespace ||
dest_llist->internal_namespace)) {
Expand Down Expand Up @@ -551,6 +560,7 @@ lazy_expunge_mail_namespaces_created(struct mail_namespace *namespaces)
if (luser->lazy_ns != NULL) {
/* we don't want to override this namespace's expunge operation. */
llist = LAZY_EXPUNGE_LIST_CONTEXT(luser->lazy_ns->list);
i_assert(llist != NULL);
llist->internal_namespace = TRUE;
} else {
/* store the the expunged mails to the specified mailbox. */
Expand All @@ -564,6 +574,7 @@ static void lazy_expunge_user_deinit(struct mail_user *user)
{
struct lazy_expunge_mail_user *luser = LAZY_EXPUNGE_USER_CONTEXT(user);

i_assert(luser != NULL);
/* mail_namespaces_created hook isn't necessarily ever called */
if (luser->lazy_ns != NULL)
mail_namespace_unref(&luser->lazy_ns);
Expand Down

0 comments on commit fc4557f

Please sign in to comment.