]> git.notmuchmail.org Git - notmuch/commitdiff
notmuch_database_add_message: Do not return a message on failure.
authorCarl Worth <cworth@cworth.org>
Tue, 27 Oct 2009 23:19:20 +0000 (16:19 -0700)
committerCarl Worth <cworth@cworth.org>
Tue, 27 Oct 2009 23:19:20 +0000 (16:19 -0700)
The recent, disastrous failure of "notmuch new" would have been
avoided with this change. The new_command function was basically
assuming that it would only get a message object on success so
wasn't destroying the message in the other cases.

database.cc
notmuch.h

index 8d477eca069abb7e3d1619d5881d3b3ad8d44469..0fd0bdadf8103366b4c2f95924926d1f532df0ca 100644 (file)
@@ -836,6 +836,9 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
     const char *from, *to, *subject, *old_filename;
     char *message_id;
 
+    if (message_ret)
+       *message_ret = NULL;
+
     message_file = notmuch_message_file_open (filename);
     if (message_file == NULL) {
        ret = NOTMUCH_STATUS_FILE_ERROR;
@@ -932,7 +935,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
 
   DONE:
     if (message) {
-       if (message_ret)
+       if (ret == NOTMUCH_STATUS_SUCCESS && message_ret)
            *message_ret = message;
        else
            notmuch_message_destroy (message);
index 7e83d23941be6e9309e63b0edeed25f83da29640..f4e59ab2ca47f47df30c81fba7323f3605b0033f 100644 (file)
--- a/notmuch.h
+++ b/notmuch.h
@@ -252,10 +252,11 @@ notmuch_database_get_timestamp (notmuch_database_t *database,
  * reference the filename, and will not copy the entire contents of
  * the file.
  *
- * If 'message' is not NULL, then '*message' will be initialized to a
- * message object that can be used for things such as adding tags to
- * the just-added message. The user should call
- * notmuch_message_destroy when done with the message.
+ * If 'message' is not NULL, then, on successful return '*message'
+ * will be initialized to a message object that can be used for things
+ * such as adding tags to the just-added message. The user should call
+ * notmuch_message_destroy when done with the message. On any failure
+ * '*message' will be set to NULL.
  *
  * Return value:
  *