]> granicus.if.org Git - neomutt/commitdiff
notmuch: check for long run during db free
authorAustin Ray <austin@austinray.io>
Wed, 14 Nov 2018 02:12:09 +0000 (21:12 -0500)
committerRichard Russon <rich@flatcap.org>
Tue, 4 Dec 2018 13:19:26 +0000 (13:19 +0000)
`nm_db_release(...)` should protect against freeing a long run database.
Prior to this commit, it was up to the programmer to ensure that a long
run database was not released.

The commit moves the check into `nm_db_release(...)` and removes the
checks elsewhere to reduce unnecessary, repeated checks.

notmuch/mutt_notmuch.c
notmuch/nm_db.c

index cd28eb89ced73b8df22754d19afd3aa8ca5eca7b..7786ba861f5148569ed26a1ea828f40dbf47b529 100644 (file)
@@ -597,8 +597,7 @@ static notmuch_query_t *get_query(struct Mailbox *m, bool writable)
   mutt_debug(2, "nm: query successfully initialized (%s)\n", str);
   return q;
 err:
-  if (!nm_db_is_longrun(m))
-    nm_db_release(m);
+  nm_db_release(m);
   return NULL;
 }
 
@@ -1637,8 +1636,8 @@ int nm_read_entire_thread(struct Context *ctx, struct Email *e)
 done:
   if (q)
     notmuch_query_destroy(q);
-  if (!nm_db_is_longrun(m))
-    nm_db_release(m);
+
+  nm_db_release(m);
 
   if (m->msg_count == mdata->oldmsgcount)
     mutt_message(_("No more messages in the thread"));
@@ -1853,8 +1852,7 @@ int nm_update_filename(struct Mailbox *m, const char *old, const char *new, stru
 
   int rc = rename_filename(m, old, new, e);
 
-  if (!nm_db_is_longrun(m))
-    nm_db_release(m);
+  nm_db_release(m);
   m->mtime.tv_sec = time(NULL);
   m->mtime.tv_nsec = 0;
   return rc;
@@ -2028,8 +2026,8 @@ done:
     notmuch_message_destroy(msg);
   if (trans == 1)
     nm_db_trans_end(m);
-  if (!nm_db_is_longrun(m))
-    nm_db_release(m);
+
+  nm_db_release(m);
   return rc;
 }
 
@@ -2078,8 +2076,7 @@ done:
   if (tags)
     notmuch_tags_destroy(tags);
 
-  if (!nm_db_is_longrun(m))
-    nm_db_release(m);
+  nm_db_release(m);
 
   mutt_debug(1, "nm: get all tags done [rc=%d tag_count=%u]\n", rc, *tag_count);
   return rc;
@@ -2165,8 +2162,7 @@ static int nm_mbox_open(struct Mailbox *m, struct Context *ctx)
     notmuch_query_destroy(q);
   }
 
-  if (!nm_db_is_longrun(m))
-    nm_db_release(m);
+  nm_db_release(m);
 
   m->mtime.tv_sec = time(NULL);
   m->mtime.tv_nsec = 0;
@@ -2295,8 +2291,7 @@ done:
   if (q)
     notmuch_query_destroy(q);
 
-  if (!nm_db_is_longrun(m))
-    nm_db_release(m);
+  nm_db_release(m);
 
   m->mtime.tv_sec = time(NULL);
   m->mtime.tv_nsec = 0;
@@ -2389,8 +2384,8 @@ static int nm_mbox_sync(struct Context *ctx, int *index_hint)
   mutt_str_strfcpy(m->path, uri, sizeof(m->path));
   m->magic = MUTT_NOTMUCH;
 
-  if (!nm_db_is_longrun(m))
-    nm_db_release(m);
+  nm_db_release(m);
+
   if (changed)
   {
     m->mtime.tv_sec = time(NULL);
@@ -2500,8 +2495,7 @@ static int nm_tags_commit(struct Mailbox *m, struct Email *e, char *buf)
   rc = 0;
   e->changed = true;
 done:
-  if (!nm_db_is_longrun(m))
-    nm_db_release(m);
+  nm_db_release(m);
   if (e->changed)
   {
     m->mtime.tv_sec = time(NULL);
index f5748ec6706b50139fd24e91c7849ea644a5fe9d..1fd7f3490a809a455489aa8ab6e76212ac94fc6b 100644 (file)
@@ -162,7 +162,7 @@ notmuch_database_t *nm_db_get(struct Mailbox *m, bool writable)
 int nm_db_release(struct Mailbox *m)
 {
   struct NmAccountData *adata = nm_adata_get(m);
-  if (!adata || !adata->db)
+  if (!adata || !adata->db || nm_db_is_longrun(m))
     return -1;
 
   mutt_debug(1, "nm: db close\n");