pidgin: a65c9ee5: Try to be polite and free stuff associat...

markdoliner at pidgin.im markdoliner at pidgin.im
Mon Apr 12 02:52:55 EDT 2010


-----------------------------------------------------------------
Revision: a65c9ee5c5782d7276caae4991630797f79a2ce8
Ancestor: 3574e71d26419f0eb9995f57e3d422911e6aaea0
Author: markdoliner at pidgin.im
Date: 2010-04-12T06:48:14
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/a65c9ee5c5782d7276caae4991630797f79a2ce8

Modified files:
        pidgin/gtkmain.c

ChangeLog: 

Try to be polite and free stuff associated with our signal watcher pipes
(even though it doesn't really matter because we're exiting)

-------------- next part --------------
============================================================
--- pidgin/gtkmain.c	5bdec07625f8da7e887d82b3c215b91384dbfcc5
+++ pidgin/gtkmain.c	d1d414d9a014e21b888358aac7494ffca725c1ac
@@ -167,7 +167,7 @@ clean_pid(void)
 
 	if ((pid == (pid_t) - 1) && (errno != ECHILD)) {
 		char errmsg[BUFSIZ];
-		snprintf(errmsg, BUFSIZ, "Warning: waitpid() returned %d", pid);
+		snprintf(errmsg, sizeof(errmsg), "Warning: waitpid() returned %d", pid);
 		perror(errmsg);
 	}
 }
@@ -539,10 +539,11 @@ int main(int argc, char *argv[])
 	char errmsg[BUFSIZ];
 	GIOChannel *signal_channel;
 	GIOStatus signal_status;
+	guint signal_channel_watcher;
 #ifndef DEBUG
 	char *segfault_message_tmp;
 #endif
-	GError *error = NULL;
+	GError *error;
 #endif
 	int opt;
 	gboolean gui_check;
@@ -608,6 +609,7 @@ int main(int argc, char *argv[])
 		/* we have to convert the message (UTF-8 to console
 		   charset) early because after a segmentation fault
 		   it's not a good practice to allocate memory */
+		error = NULL;
 		segfault_message = g_locale_from_utf8(segfault_message_tmp,
 						      -1, NULL, NULL, &error);
 		if (segfault_message != NULL) {
@@ -652,7 +654,8 @@ int main(int argc, char *argv[])
 				"binary: %s", error->message);
 		exit(1);
 	}
-	g_io_add_watch(signal_channel, G_IO_IN, mainloop_sighandler, NULL);
+	signal_channel_watcher = g_io_add_watch(signal_channel, G_IO_IN, mainloop_sighandler, NULL);
+	g_io_channel_unref(signal_channel);
 
 	/* Let's not violate any PLA's!!!! */
 	/* jseymour: whatever the fsck that means */
@@ -660,31 +663,31 @@ int main(int argc, char *argv[])
 	 * useful signals like SIGCHLD, so we unblock all the ones we  *
 	 * declare a handler for. thanks JSeymour and Vann.            */
 	if (sigemptyset(&sigset)) {
-		snprintf(errmsg, BUFSIZ, "Warning: couldn't initialise empty signal set");
+		snprintf(errmsg, sizeof(errmsg), "Warning: couldn't initialise empty signal set");
 		perror(errmsg);
 	}
 	for(sig_indx = 0; catch_sig_list[sig_indx] != -1; ++sig_indx) {
 		if((prev_sig_disp = signal(catch_sig_list[sig_indx], sighandler)) == SIG_ERR) {
-			snprintf(errmsg, BUFSIZ, "Warning: couldn't set signal %d for catching",
+			snprintf(errmsg, sizeof(errmsg), "Warning: couldn't set signal %d for catching",
 				catch_sig_list[sig_indx]);
 			perror(errmsg);
 		}
 		if(sigaddset(&sigset, catch_sig_list[sig_indx])) {
-			snprintf(errmsg, BUFSIZ, "Warning: couldn't include signal %d for unblocking",
+			snprintf(errmsg, sizeof(errmsg), "Warning: couldn't include signal %d for unblocking",
 				catch_sig_list[sig_indx]);
 			perror(errmsg);
 		}
 	}
 	for(sig_indx = 0; ignore_sig_list[sig_indx] != -1; ++sig_indx) {
 		if((prev_sig_disp = signal(ignore_sig_list[sig_indx], SIG_IGN)) == SIG_ERR) {
-			snprintf(errmsg, BUFSIZ, "Warning: couldn't set signal %d to ignore",
+			snprintf(errmsg, sizeof(errmsg), "Warning: couldn't set signal %d to ignore",
 				ignore_sig_list[sig_indx]);
 			perror(errmsg);
 		}
 	}
 
 	if (sigprocmask(SIG_UNBLOCK, &sigset, NULL)) {
-		snprintf(errmsg, BUFSIZ, "Warning: couldn't unblock signals");
+		snprintf(errmsg, sizeof(errmsg), "Warning: couldn't unblock signals");
 		perror(errmsg);
 	}
 #endif
@@ -977,6 +980,9 @@ int main(int argc, char *argv[])
 
 #ifdef HAVE_SIGNAL_H
 	g_free(segfault_message);
+	g_source_remove(signal_channel_watcher);
+	close(signal_sockets[0]);
+	close(signal_sockets[1]);
 #endif
 
 #ifdef _WIN32


More information about the Commits mailing list