changeset 29710:ac49f12cddeb

Try to be polite and free stuff associated with our signal watcher pipes (even though it doesn't really matter because we're exiting)
author Mark Doliner <mark@kingant.net>
date Mon, 12 Apr 2010 06:48:14 +0000
parents fd2d15e57763
children 87b166bd3760
files pidgin/gtkmain.c
diffstat 1 files changed, 14 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtkmain.c	Mon Apr 12 06:45:18 2010 +0000
+++ b/pidgin/gtkmain.c	Mon Apr 12 06:48:14 2010 +0000
@@ -167,7 +167,7 @@
 
 	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 @@
 	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 @@
 		/* 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 @@
 				"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 @@
 	 * 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 @@
 
 #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