Browse Source

Fix an unimportant memory leak

Přemysl Janouch 2 months ago
parent
commit
fcc0c3ef2d
Signed by: Přemysl Janouch <p@janouch.name> GPG Key ID: A0420B94F92B9493
1 changed files with 15 additions and 6 deletions
  1. 15
    6
      src/sdtui.c

+ 15
- 6
src/sdtui.c View File

@@ -58,6 +58,15 @@ unichar_width (gunichar ch)
58 58
 	return 1 + g_unichar_iswide (ch);
59 59
 }
60 60
 
61
+static guint
62
+add_read_watch (int fd, GIOFunc func, gpointer user_data)
63
+{
64
+	GIOChannel *channel = g_io_channel_unix_new (fd);
65
+	guint res = g_io_add_watch (channel, G_IO_IN, func, user_data);
66
+	g_io_channel_unref (channel);
67
+	return res;
68
+}
69
+
61 70
 // At times, GLib even with its sheer size is surprisingly useless,
62 71
 // and I need to port some code over from "liberty".
63 72
 
@@ -2083,8 +2092,8 @@ selection_watch_init (SelectionWatch *self, Application *app)
2083 2092
 		XCB_XFIXES_SELECTION_EVENT_MASK_SELECTION_CLIENT_CLOSE);
2084 2093
 
2085 2094
 	(void) xcb_flush (self->X);
2086
-	self->watch = g_io_add_watch (g_io_channel_unix_new
2087
-		(xcb_get_file_descriptor (self->X)), G_IO_IN, process_x11, self);
2095
+	self->watch = add_read_watch
2096
+		(xcb_get_file_descriptor (self->X), process_x11, self);
2088 2097
 
2089 2098
 	// Never NULL so that we don't need to care about pointer validity
2090 2099
 	self->buffer = g_string_new (NULL);
@@ -2291,10 +2300,10 @@ G_GNUC_END_IGNORE_DEPRECATIONS
2291 2300
 	// Message loop
2292 2301
 	guint watch_term  = g_unix_signal_add (SIGTERM, on_terminated, &app);
2293 2302
 	guint watch_int   = g_unix_signal_add (SIGINT,  on_terminated, &app);
2294
-	guint watch_stdin = g_io_add_watch (g_io_channel_unix_new (STDIN_FILENO),
2295
-		G_IO_IN, process_stdin_input, &app);
2296
-	guint watch_winch = g_io_add_watch (g_io_channel_unix_new (g_winch_pipe[0]),
2297
-		G_IO_IN, process_winch_input, &app);
2303
+	guint watch_stdin = add_read_watch
2304
+		(STDIN_FILENO, process_stdin_input, &app);
2305
+	guint watch_winch = add_read_watch
2306
+		(g_winch_pipe[0], process_winch_input, &app);
2298 2307
 
2299 2308
 #ifdef WITH_X11
2300 2309
 	SelectionWatch sw;

Loading…
Cancel
Save