libi3/root_atom_contents: Free xcb reply structures
Patch status: merged
Patch by Lancelot SIX
Long description:
Free memory allocated during xcb calls.
To apply this patch, use:
curl http://cr.i3wm.org/patch/329/raw.patch | git am
b/libi3/root_atom_contents.c
| 14 |
@@ -9,6 +9,7 @@ |
| 15 |
#include <string.h> |
| 16 |
#include <stdbool.h> |
| 17 |
#include <limits.h> |
| 18 |
+#include <stdlib.h> |
| 19 |
|
| 20 |
#include <xcb/xcb.h> |
| 21 |
#include <xcb/xcb_aux.h> |
| 22 |
@@ -51,20 +52,35 @@ char *root_atom_contents(const char *atomname, xcb_connection_t *provided_conn, |
| 23 |
prop_cookie = xcb_get_property_unchecked(conn, false, root, atom_reply->atom, |
| 24 |
XCB_GET_PROPERTY_TYPE_ANY, 0, PATH_MAX); |
| 25 |
prop_reply = xcb_get_property_reply(conn, prop_cookie, NULL); |
| 26 |
- if (prop_reply == NULL || xcb_get_property_value_length(prop_reply) == 0) |
| 27 |
+ if (prop_reply == NULL) {
|
| 28 |
+ free(atom_reply); |
| 29 |
return NULL; |
| 30 |
+ } |
| 31 |
+ if (xcb_get_property_value_length(prop_reply) == 0) {
|
| 32 |
+ free(atom_reply); |
| 33 |
+ free(prop_reply); |
| 34 |
+ return NULL; |
| 35 |
+ } |
| 36 |
if (prop_reply->type == XCB_ATOM_CARDINAL) {
|
| 37 |
/* We treat a CARDINAL as a >= 32-bit unsigned int. The only CARDINAL |
| 38 |
* we query is I3_PID, which is 32-bit. */ |
| 39 |
- if (asprintf(&content, "%u", *((unsigned int*)xcb_get_property_value(prop_reply))) == -1) |
| 40 |
+ if (asprintf(&content, "%u", *((unsigned int*)xcb_get_property_value(prop_reply))) == -1) {
|
| 41 |
+ free(atom_reply); |
| 42 |
+ free(prop_reply); |
| 43 |
return NULL; |
| 44 |
+ } |
| 45 |
} else {
|
| 46 |
if (asprintf(&content, "%.*s", xcb_get_property_value_length(prop_reply), |
| 47 |
- (char*)xcb_get_property_value(prop_reply)) == -1) |
| 48 |
+ (char*)xcb_get_property_value(prop_reply)) == -1) {
|
| 49 |
+ free(atom_reply); |
| 50 |
+ free(prop_reply); |
| 51 |
return NULL; |
| 52 |
+ } |
| 53 |
} |
| 54 |
if (provided_conn == NULL) |
| 55 |
xcb_disconnect(conn); |
| 56 |
+ free(atom_reply); |
| 57 |
+ free(prop_reply); |
| 58 |
return content; |
| 59 |
} |
| 60 |
|