mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-22 02:48:08 +01:00
Fix _notmuch_message_create to catch Xapian DocNotFoundError.
This function is only supposed to be called with a doc_id that was queried from the database already. So there's an internal error if no document with that doc_id can be found in the database. In that case, return NULL.
This commit is contained in:
parent
17548e314a
commit
69b25a75ec
1 changed files with 22 additions and 1 deletions
23
message.cc
23
message.cc
|
@ -108,6 +108,22 @@ _notmuch_message_destructor (notmuch_message_t *message)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Create a new notmuch_message_t object for an existing document in
|
||||
* the database.
|
||||
*
|
||||
* Here, 'talloc owner' is an optional talloc context to which the new
|
||||
* message will belong. This allows for the caller to not bother
|
||||
* calling notmuch_message_destroy on the message, and no that all
|
||||
* memory will be reclaimed with 'talloc_owner' is free. The caller
|
||||
* still can call notmuch_message_destroy when finished with the
|
||||
* message if desired.
|
||||
*
|
||||
* The 'talloc_owner' argument can also be NULL, in which case the
|
||||
* caller *is* responsible for calling notmuch_message_destroy.
|
||||
*
|
||||
* If no document exists in the database with document ID of 'doc_id'
|
||||
* then this function returns NULL.
|
||||
*/
|
||||
notmuch_message_t *
|
||||
_notmuch_message_create (const void *talloc_owner,
|
||||
notmuch_database_t *notmuch,
|
||||
|
@ -127,7 +143,12 @@ _notmuch_message_create (const void *talloc_owner,
|
|||
|
||||
talloc_set_destructor (message, _notmuch_message_destructor);
|
||||
|
||||
message->doc = notmuch->xapian_db->get_document (doc_id);
|
||||
try {
|
||||
message->doc = notmuch->xapian_db->get_document (doc_id);
|
||||
} catch (const Xapian::DocNotFoundError &error) {
|
||||
talloc_free (message);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue