Skip to content

Commit

Permalink
jmap_contact.c:_contacts_set() memory leak
Browse files Browse the repository at this point in the history
• account in http_dblookup.c that mboxname_abook() cannot return NULL.
  • Loading branch information
dilyanpalauzov committed Aug 19, 2023
1 parent bb6a880 commit 93b9b60
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
3 changes: 0 additions & 3 deletions imap/http_dblookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ static int get_email2uids(struct transaction_t *txn __attribute__((unused)),
}

mboxname = mboxname_abook(userid, mailbox);
if (!mboxname) goto done;

mboxlist_lookup(mboxname, &mbentry, NULL);
if (!mbentry) goto done;
Expand Down Expand Up @@ -202,7 +201,6 @@ static int get_email2details(struct transaction_t *txn __attribute__((unused)),
}

mboxname = mboxname_abook(userid, mailbox);
if (!mboxname) goto done;

mboxlist_lookup(mboxname, &mbentry, NULL);
if (!mbentry) goto done;
Expand Down Expand Up @@ -266,7 +264,6 @@ static int get_uid2groups(struct transaction_t *txn,
}

mboxname = mboxname_abook(userid, mailbox);
if (!mboxname) goto done;

mboxlist_lookup(mboxname, &mbentry, NULL);
if (!mbentry) goto done;
Expand Down
5 changes: 4 additions & 1 deletion imap/jmap_contact.c
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ static void _contacts_set(struct jmap_req *req, unsigned kind)

json_t *abookid = json_object_get(arg, "addressbookId");
if (abookid && json_string_value(abookid)) {
const char *mboxname =
char *mboxname =
mboxname_abook(req->accountid, json_string_value(abookid));
if (mbentry && strcmp(mboxname, mbentry->name)) {
/* move */
Expand All @@ -1076,16 +1076,19 @@ static void _contacts_set(struct jmap_req *req, unsigned kind)
"properties", "addressbookId");
json_object_set_new(set.not_updated, uid, err);
mboxlist_entry_free(&mbentry);
free(mboxname);
continue;
}
r = jmap_openmbox(req, mboxname, &newmailbox, 1);
if (r) {
syslog(LOG_ERR, "IOERROR: failed to open %s", mboxname);
mboxlist_entry_free(&mbentry);
free(mboxname);
goto done;
}
do_move = 1;
}
free(mboxname);
json_object_del(arg, "addressbookId");
}

Expand Down
2 changes: 1 addition & 1 deletion imap/mboxname.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ void mboxname_id_hash(char *buf, size_t buf_len,
char *mboxname_to_userid(const char *mboxname);
char *mboxname_user_mbox(const char *userid, const char *subfolder);
char *mboxname_user_mbox_external(const char *userid, const char *extsubfolder);
char *mboxname_abook(const char *userid, const char *collection);
__attribute__((malloc, warn_unused_result, returns_nonnull)) char *mboxname_abook(const char *userid, const char *collection);
char *mboxname_cal(const char *userid, const char *collection);
char *mboxname_drive(const char *userid, const char *collection);

Expand Down

0 comments on commit 93b9b60

Please sign in to comment.