Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

IMAP: fix possible data race

  • Loading branch information...
commit 3618637ed7629422d200a20448038010640fdaab 1 parent 9bed91b
@pjstevns authored
View
5 src/dbmail-imapsession.c
@@ -94,6 +94,7 @@ ImapSession * dbmail_imap_session_new(void)
ImapSession * self;
self = g_new0(ImapSession,1);
+ g_mutex_init(&self->lock);
self->state = CLIENTSTATE_NON_AUTHENTICATED;
self->args = g_new0(char *, MAX_ARGS);
self->buff = g_string_new("");
@@ -581,7 +582,9 @@ void _send_headers(ImapSession *self, const body_fetch *bodyfetch, gboolean not)
}
g_string_free(ts,TRUE);
+ ts = NULL;
g_free(tmp);
+ tmp = NULL;
}
@@ -1524,7 +1527,9 @@ int dbmail_imap_session_set_state(ImapSession *self, ClientState_T state)
}
TRACE(TRACE_DEBUG,"[%p] state [%d]->[%d]", self, self->state, state);
+ g_mutex_lock(&self->lock);
self->state = state;
+ g_mutex_unlock(&self->lock);
return 0;
}
View
1  src/dbmail-imapsession.h
@@ -17,6 +17,7 @@ typedef struct cmd_t *cmd_t;
/* ImapSession definition */
typedef struct {
+ GMutex lock;
ClientBase_T *ci;
Capa_T preauth_capa; // CAPABILITY
Capa_T capa; // CAPABILITY
View
1  src/dm_capa.c
@@ -48,6 +48,7 @@ static void capa_update(T A)
GString *t = g_list_join(A->current_set, " ");
strncpy((char *)A->capabilities, t->str, MAX_CAPASIZE-1);
g_string_free(t, TRUE);
+ t = NULL;
A->dirty = FALSE;
}
}
View
6 src/imap4.c
@@ -186,6 +186,7 @@ static void imap_session_bailout(ImapSession *session)
void socket_write_cb(int fd, short what, void *arg)
{
ImapSession *session = (ImapSession *)arg;
+ ClientState_T state;
#ifdef DEBUG
TRACE(TRACE_DEBUG,"[%p] on [%d] event: %s%s%s%s", session,
(int) fd,
@@ -195,7 +196,10 @@ void socket_write_cb(int fd, short what, void *arg)
(what&EV_SIGNAL) ? " signal": ""
);
#endif
- switch(session->state) {
+ g_mutex_lock(&session->lock);
+ state = session->state;
+ g_mutex_unlock(&session->lock);
+ switch(state) {
case CLIENTSTATE_QUIT_QUEUED:
break; // ignore
case CLIENTSTATE_LOGOUT:
Please sign in to comment.
Something went wrong with that request. Please try again.