i3 - improved tiling WM


Bugfix: ipc_receive_message reply leak

Patch status: merged

Patch by Tony Crisci

Long description:

The function ipc_recv_message in libi3 allocates memory to the location
of the `message` reply in src/ipc_receive_message.c with malloc and must
be freed.

This memory leak was found using valgrind.

To apply this patch, use:
curl http://cr.i3wm.org/patch/450/raw.patch | git am

b/src/ipc.c

18
@@ -894,14 +894,16 @@ handler_t handlers[8] = {
19
 static void ipc_receive_message(EV_P_ struct ev_io *w, int revents) {
20
     uint32_t message_type;
21
     uint32_t message_length;
22
-    uint8_t *message;
23
+    uint8_t *message = NULL;
24
 
25
     int ret = ipc_recv_message(w->fd, &message_type, &message_length, &message);
26
     /* EOF or other error */
27
     if (ret < 0) {
28
         /* Was this a spurious read? See ev(3) */
29
-        if (ret == -1 && errno == EAGAIN)
30
+        if (ret == -1 && errno == EAGAIN) {
31
+            FREE(message);
32
             return;
33
+        }
34
 
35
         /* If not, there was some kind of error. We don’t bother
36
          * and close the connection */
37
@@ -924,6 +926,7 @@ static void ipc_receive_message(EV_P_ struct ev_io *w, int revents) {
38
 
39
         ev_io_stop(EV_A_ w);
40
         free(w);
41
+        FREE(message);
42
 
43
         DLOG("IPC: client disconnected\n");
44
         return;
45
@@ -935,6 +938,8 @@ static void ipc_receive_message(EV_P_ struct ev_io *w, int revents) {
46
         handler_t h = handlers[message_type];
47
         h(w->fd, message, 0, message_length, message_type);
48
     }
49
+
50
+    FREE(message);
51
 }
52
 
53
 /*