Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix segfault on opening multiple threads for one entry in thread list #696

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions src/db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,6 @@ namespace Astroid {
string query_s = "thread:" + thread_id;

notmuch_query_t * query = notmuch_query_create (nm_db, query_s.c_str());
notmuch_thread_t * nm_thread;
notmuch_threads_t * nm_threads;
notmuch_status_t st = NOTMUCH_STATUS_SUCCESS;

Expand All @@ -469,13 +468,8 @@ namespace Astroid {
int c = 0;
for ( ; notmuch_threads_valid (nm_threads);
notmuch_threads_move_to_next (nm_threads)) {
if (c > 0) {
LOG (error) << "db: got more than one thread for thread id.";
throw invalid_argument ("db: got more than one thread for thread id.");
}

nm_thread = notmuch_threads_get (nm_threads);

notmuch_thread_t* nm_thread = notmuch_threads_get (nm_threads);
func (nm_thread);
c++;
}

Expand All @@ -486,9 +480,6 @@ namespace Astroid {
return;
}

/* call function */
func (nm_thread);

/* free resources */
notmuch_query_destroy (query);
}
Expand Down
50 changes: 23 additions & 27 deletions src/modes/thread_index/query_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -336,35 +336,31 @@ namespace Astroid {
Gtk::TreeViewColumn *c;
list_view->get_cursor (path, c);

auto iter = list_store->prepend ();
Gtk::ListStore::Row newrow = *iter;

NotmuchThread * t;

db->on_thread (thread_id, [&t](notmuch_thread_t *nmt) {

t = new NotmuchThread (nmt);

});

newrow[list_store->columns.newest_date] = t->newest_date;
newrow[list_store->columns.oldest_date] = t->oldest_date;
newrow[list_store->columns.thread_id] = t->thread_id;
newrow[list_store->columns.thread] = Glib::RefPtr<NotmuchThread>(t);

/* check if we should select it (if this is the only item) */
if (list_store->children().size() == 1) {
if (!in_destructor)
first_thread_ready.emit ();
} else {

if (path == Gtk::TreePath ("0")) {
Gtk::TreePath addpath = list_store->get_path (iter);
if (addpath <= path) {
list_view->set_cursor (addpath);
db->on_thread (thread_id, [this, &path](notmuch_thread_t *nmt) {
auto iter = list_store->prepend();
Gtk::ListStore::Row newrow = *iter;
NotmuchThread* t = new NotmuchThread (nmt);

newrow[list_store->columns.newest_date] = t->newest_date;
newrow[list_store->columns.oldest_date] = t->oldest_date;
newrow[list_store->columns.thread_id] = t->thread_id;
newrow[list_store->columns.thread] = Glib::RefPtr<NotmuchThread>(t);

/* check if we should select it (if this is the only item) */
if (list_store->children().size() == 1) {
if (!in_destructor)
first_thread_ready.emit ();
} else {

if (path == Gtk::TreePath ("0")) {
Gtk::TreePath addpath = list_store->get_path (iter);
if (addpath <= path) {
list_view->set_cursor (addpath);
}
}
}
}
}
});

changed = true;
}
Expand Down