[PATCH] : forgotten locks corrected (in send.c)



	Hi all,
attached is a patch to add locking of libmutt in several functions of the
libbalsa/send.c, please note that this patch has nothing to do with the
others (in fact I can tell that it won't apply after the cleanups series).
It's just a rapid patch to fix locking bugs.

in libbalsa_message_postpone :
	unlock libmutt to call encode_descriptions because this is a
libbalsa function

in libbalsa_create_msg :
	add the complete locking of libmutt, it was inexistant

This patch is against 1.2.0
Bye
Manu
--- balsa-1.2.0/libbalsa/send.c	Thu Sep  6 15:37:38 2001
+++ test2/balsa-1.2.0/libbalsa/send.c	Thu Oct 18 15:00:06 2001
@@ -1212,7 +1212,9 @@
     }
 
     mutt_prepare_envelope(msg->env);
+    libbalsa_unlock_mutt();
     encode_descriptions(msg->content);
+    libbalsa_lock_mutt();
 
     if ((reply_message != NULL) && (reply_message->mailbox != NULL))
 	/* Just saves the message ID, mailbox type and mailbox name. We could
@@ -1311,6 +1313,7 @@
 
     message2HEADER(message, msg);
 
+    libbalsa_lock_mutt();
     /* If the message has references set, add them to he envelope */
     if (message->references != NULL) {
 	list = message->references;
@@ -1334,7 +1337,7 @@
 	msg->env->userhdrs = in_reply_to;
     }
 
-
+    libbalsa_unlock_mutt();
     if (message->mailbox)
 	libbalsa_message_body_ref(message);
 
@@ -1344,6 +1347,7 @@
     while (last && last->next)
 	last = last->next;
 
+    libbalsa_lock_mutt();
     while (body) {
 	FILE *tempfp = NULL;
 	newbdy = NULL;
@@ -1358,12 +1362,14 @@
 
 		/* Do this here because we don't want
 		 * to use libmutt's mime types */
+		libbalsa_unlock_mutt();
 		mime_type =
 		    libbalsa_lookup_mime_type((const gchar *) body->
 					      filename);
 		/* use BASE64 encoding for non-text mime types */
 		if(strcasecmp(mime_type[0],"text") != 0)
 		    newbdy->encoding = ENCBASE64;
+		libbalsa_lock_mutt();
 		newbdy->type = mutt_check_mime_type(mime_type[0]);
 		newbdy->type = mutt_check_mime_type(mime_type[0]);
 		g_free(newbdy->subtype);
@@ -1371,7 +1377,9 @@
 		g_strfreev(mime_type);
 	    }
 	} else if (body->buffer) {
+	    libbalsa_unlock_mutt();
 	    newbdy = add_mutt_body_plain(body->charset, encoding);
+	    libbalsa_lock_mutt();
 #ifdef BALSA_MDN_REPLY
 	    if (body->mime_type) {
 		/* change the type and subtype within the mutt body */
@@ -1380,10 +1388,8 @@
 		type = g_strdup (body->mime_type);
 		if ((subtype = strchr (type, '/'))) {
 		    *subtype++ = 0;
-		    libbalsa_lock_mutt();
 		    newbdy->type = mutt_check_mime_type (type);
 		    newbdy->subtype = g_strdup(subtype);
-		    libbalsa_unlock_mutt();
 		}
 		g_free (type);
 	    }
@@ -1415,12 +1421,13 @@
     }
 
     mutt_prepare_envelope(msg->env);
-
+    libbalsa_unlock_mutt();
     encode_descriptions(msg->content);
 
 /* We create the message in MIME format here, we use the same format 
  * for local delivery that for SMTP */
     if (queu == 0) {
+	libbalsa_lock_mutt();
 	mutt_mktemp(tmpfile);
 	if ((tempfp = safe_fopen(tmpfile, "w")) == NULL)
 	    return (-1);
@@ -1429,6 +1436,7 @@
 	fputc('\n', tempfp);	/* tie off the header. */
 
 	if ((mutt_write_mime_body(msg->content, tempfp) == -1)) {
+	    libbalsa_unlock_mutt();
 	    fclose(tempfp);
 	    unlink(tmpfile);
 	    return (-1);
@@ -1437,6 +1445,7 @@
 
 	if (fclose(tempfp) != 0) {
 	    mutt_perror(tmpfile);
+	    libbalsa_unlock_mutt();
 	    unlink(tmpfile);
 	    return (-1);
 	}
@@ -1444,6 +1453,7 @@
     } else {
 	/* the message is in the queue */
 
+	libbalsa_lock_mutt();
 	msg_tmp =
 	    CLIENT_CONTEXT(message->mailbox)->hdrs[message->msgno];
 	mutt_parse_mime_message(CLIENT_CONTEXT(message->mailbox),
@@ -1453,8 +1463,10 @@
 			    msg_tmp->msgno);
 
 	mutt_mktemp(tmpfile);
-	if ((tempfp = safe_fopen(tmpfile, "w")) == NULL)
+	if ((tempfp = safe_fopen(tmpfile, "w")) == NULL) {
+	    libbalsa_unlock_mutt();
 	    return FALSE;
+	}
 
 	_mutt_copy_message(tempfp, mensaje->fp, msg_tmp,
 			   msg_tmp->content, 0, CH_NOSTATUS);
@@ -1462,6 +1474,7 @@
 	if (fclose(tempfp) != 0) {
 	    mutt_perror(tmpfile);
 	    unlink(tmpfile);
+	    libbalsa_unlock_mutt();
 	    if (message->mailbox)
 		libbalsa_message_body_unref(message);
 	    return FALSE;
@@ -1469,6 +1482,7 @@
 
     }
 
+    libbalsa_unlock_mutt();
     if (message->mailbox)
 	libbalsa_message_body_unref(message);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]