Fix a core dump under OpenBSD

Based on a patch by StAlphonsos
This commit is contained in:
djcb 2015-03-06 00:12:34 +02:00
parent 9799d76fdb
commit baebd53fb8
3 changed files with 21 additions and 21 deletions

View File

@ -359,14 +359,16 @@ mu_msg_iter_get_docid (MuMsgIter *iter)
const char*
char*
mu_msg_iter_get_msgid (MuMsgIter *iter)
{
g_return_val_if_fail (iter, NULL);
g_return_val_if_fail (!mu_msg_iter_is_done(iter), NULL);
try {
return iter->msgid().c_str();
const char *msgid (iter->msgid().c_str());
return msgid ? g_strdup (msgid) : NULL;
} MU_XAPIAN_CATCH_BLOCK_RETURN (NULL);
}
@ -388,7 +390,7 @@ mu_msg_iter_get_refs (MuMsgIter *iter)
} MU_XAPIAN_CATCH_BLOCK_RETURN (NULL);
}
const char*
char*
mu_msg_iter_get_thread_id (MuMsgIter *iter)
{
g_return_val_if_fail (iter, NULL);
@ -397,7 +399,8 @@ mu_msg_iter_get_thread_id (MuMsgIter *iter)
try {
const std::string thread_id (
iter->cursor().get_document().get_value(MU_MSG_FIELD_ID_THREAD_ID).c_str());
return thread_id.empty() ? NULL : thread_id.c_str();
return thread_id.empty() ? NULL : g_strdup (thread_id.c_str());
} MU_XAPIAN_CATCH_BLOCK_RETURN (NULL);

View File

@ -145,7 +145,7 @@ void mu_msg_iter_set_preferred (MuMsgIter *iter, GHashTable *preferred_hash);
*
* @return the docid or (unsigned int)-1 in case of error
*/
unsigned int mu_msg_iter_get_docid (MuMsgIter *iter);
guint mu_msg_iter_get_docid (MuMsgIter *iter);
/**
@ -196,10 +196,10 @@ const MuMsgIterThreadInfo* mu_msg_iter_get_thread_info (MuMsgIter *iter);
*
* @param iter a valid MuMsgIter iterator
*
* @return the message-id; this only stays valid as long as the
* current iter stays valid.
* @return the message-id; free with g_free().
*/
const char* mu_msg_iter_get_msgid (MuMsgIter *iter);
char* mu_msg_iter_get_msgid (MuMsgIter *iter)
G_GNUC_WARN_UNUSED_RESULT;
/**
* get the list of references for this messages as a NULL-terminated
@ -210,7 +210,8 @@ const char* mu_msg_iter_get_msgid (MuMsgIter *iter);
* @return a NULL-terminated string array. free with g_strfreev when
* it's no longer needed.
*/
char** mu_msg_iter_get_refs (MuMsgIter *iter);
char** mu_msg_iter_get_refs (MuMsgIter *iter)
G_GNUC_WARN_UNUSED_RESULT;
/**
@ -218,15 +219,10 @@ char** mu_msg_iter_get_refs (MuMsgIter *iter);
*
* @param iter a valid MuMsgIter iterator
*
* @return the thread-id; this only stays valid as long as the
* current iter stays valid.
* @return the thread-id; free with g_free().
*/
const char* mu_msg_iter_get_thread_id (MuMsgIter *iter);
char* mu_msg_iter_get_thread_id (MuMsgIter *iter)
G_GNUC_WARN_UNUSED_RESULT;
/* FIXME */

View File

@ -414,22 +414,23 @@ static GHashTable*
get_thread_ids (MuMsgIter *iter, GHashTable **orig_set)
{
GHashTable *ids;
ids = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify)g_free, NULL);
*orig_set = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify)g_free, NULL);
while (!mu_msg_iter_is_done (iter)) {
const char *thread_id, *msgid;
unsigned docid;
char *thread_id, *msgid;
unsigned docid;
/* record the thread id for the message */
if ((thread_id = mu_msg_iter_get_thread_id (iter)))
g_hash_table_insert (ids, g_strdup (thread_id),
g_hash_table_insert (ids, thread_id,
GSIZE_TO_POINTER(TRUE));
/* record the original set */
docid = mu_msg_iter_get_docid(iter);
if (docid != 0 && (msgid = mu_msg_iter_get_msgid (iter)))
g_hash_table_insert (*orig_set, g_strdup (msgid),
g_hash_table_insert (*orig_set, msgid,
GSIZE_TO_POINTER(docid));
if (!mu_msg_iter_next (iter))