Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

IMAP: fix possible data race

  • Loading branch information...
commit 3618637ed7629422d200a20448038010640fdaab 1 parent 9bed91b
Paul J Stevens authored September 20, 2012
5  src/dbmail-imapsession.c
@@ -94,6 +94,7 @@ ImapSession * dbmail_imap_session_new(void)
94 94
 	ImapSession * self;
95 95
 
96 96
 	self = g_new0(ImapSession,1);
  97
+	g_mutex_init(&self->lock);
97 98
 	self->state = CLIENTSTATE_NON_AUTHENTICATED;
98 99
 	self->args = g_new0(char *, MAX_ARGS);
99 100
 	self->buff = g_string_new("");
@@ -581,7 +582,9 @@ void _send_headers(ImapSession *self, const body_fetch *bodyfetch, gboolean not)
581 582
 	}
582 583
 
583 584
 	g_string_free(ts,TRUE);
  585
+	ts = NULL;
584 586
 	g_free(tmp);
  587
+	tmp = NULL;
585 588
 }
586 589
 
587 590
 
@@ -1524,7 +1527,9 @@ int dbmail_imap_session_set_state(ImapSession *self, ClientState_T state)
1524 1527
 	}
1525 1528
 
1526 1529
 	TRACE(TRACE_DEBUG,"[%p] state [%d]->[%d]", self, self->state, state);
  1530
+	g_mutex_lock(&self->lock);
1527 1531
 	self->state = state;
  1532
+	g_mutex_unlock(&self->lock);
1528 1533
 
1529 1534
 	return 0;
1530 1535
 }
1  src/dbmail-imapsession.h
@@ -17,6 +17,7 @@ typedef struct cmd_t *cmd_t;
17 17
 
18 18
 /* ImapSession definition */
19 19
 typedef struct {
  20
+	GMutex lock;
20 21
 	ClientBase_T *ci;
21 22
 	Capa_T preauth_capa;   // CAPABILITY
22 23
 	Capa_T capa;   // CAPABILITY
1  src/dm_capa.c
@@ -48,6 +48,7 @@ static void capa_update(T A)
48 48
 		GString *t = g_list_join(A->current_set, " ");
49 49
 		strncpy((char *)A->capabilities, t->str, MAX_CAPASIZE-1);
50 50
 		g_string_free(t, TRUE);
  51
+		t = NULL;
51 52
 		A->dirty = FALSE;
52 53
 	}
53 54
 }
6  src/imap4.c
@@ -186,6 +186,7 @@ static void imap_session_bailout(ImapSession *session)
186 186
 void socket_write_cb(int fd, short what, void *arg)
187 187
 {
188 188
 	ImapSession *session = (ImapSession *)arg;
  189
+	ClientState_T state;
189 190
 #ifdef DEBUG
190 191
 	TRACE(TRACE_DEBUG,"[%p] on [%d] event: %s%s%s%s", session,
191 192
 			(int) fd,
@@ -195,7 +196,10 @@ void socket_write_cb(int fd, short what, void *arg)
195 196
 			(what&EV_SIGNAL)  ? " signal":  ""
196 197
 	     );
197 198
 #endif
198  
-	switch(session->state) {
  199
+	g_mutex_lock(&session->lock);
  200
+	state = session->state;
  201
+	g_mutex_unlock(&session->lock);
  202
+	switch(state) {
199 203
 		case CLIENTSTATE_QUIT_QUEUED:
200 204
 			break; // ignore
201 205
 		case CLIENTSTATE_LOGOUT:

0 notes on commit 3618637

Please sign in to comment.
Something went wrong with that request. Please try again.