diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/ipc-client.c | 9 | ||||
-rw-r--r-- | common/pango.c | 12 |
2 files changed, 15 insertions, 6 deletions
diff --git a/common/ipc-client.c b/common/ipc-client.c index 3515ef0a..13fd8a05 100644 --- a/common/ipc-client.c +++ b/common/ipc-client.c | |||
@@ -61,7 +61,7 @@ int ipc_open_socket(const char *socket_path) { | |||
61 | } | 61 | } |
62 | 62 | ||
63 | struct ipc_response *ipc_recv_response(int socketfd) { | 63 | struct ipc_response *ipc_recv_response(int socketfd) { |
64 | char data[ipc_header_size]; | 64 | char *data = malloc(sizeof(char) * ipc_header_size); |
65 | uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic)); | 65 | uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic)); |
66 | 66 | ||
67 | size_t total = 0; | 67 | size_t total = 0; |
@@ -81,6 +81,8 @@ struct ipc_response *ipc_recv_response(int socketfd) { | |||
81 | total = 0; | 81 | total = 0; |
82 | memcpy(&response->size, &data32[0], sizeof(data32[0])); | 82 | memcpy(&response->size, &data32[0], sizeof(data32[0])); |
83 | memcpy(&response->type, &data32[1], sizeof(data32[1])); | 83 | memcpy(&response->type, &data32[1], sizeof(data32[1])); |
84 | free(data); | ||
85 | |||
84 | char *payload = malloc(response->size + 1); | 86 | char *payload = malloc(response->size + 1); |
85 | if (!payload) { | 87 | if (!payload) { |
86 | goto error_2; | 88 | goto error_2; |
@@ -99,6 +101,7 @@ struct ipc_response *ipc_recv_response(int socketfd) { | |||
99 | return response; | 101 | return response; |
100 | error_2: | 102 | error_2: |
101 | free(response); | 103 | free(response); |
104 | free(payload); | ||
102 | error_1: | 105 | error_1: |
103 | wlr_log(WLR_ERROR, "Unable to allocate memory for IPC response"); | 106 | wlr_log(WLR_ERROR, "Unable to allocate memory for IPC response"); |
104 | return NULL; | 107 | return NULL; |
@@ -110,7 +113,7 @@ void free_ipc_response(struct ipc_response *response) { | |||
110 | } | 113 | } |
111 | 114 | ||
112 | char *ipc_single_command(int socketfd, uint32_t type, const char *payload, uint32_t *len) { | 115 | char *ipc_single_command(int socketfd, uint32_t type, const char *payload, uint32_t *len) { |
113 | char data[ipc_header_size]; | 116 | char *data = malloc(sizeof(char) * ipc_header_size); |
114 | uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic)); | 117 | uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic)); |
115 | memcpy(data, ipc_magic, sizeof(ipc_magic)); | 118 | memcpy(data, ipc_magic, sizeof(ipc_magic)); |
116 | memcpy(&data32[0], len, sizeof(*len)); | 119 | memcpy(&data32[0], len, sizeof(*len)); |
@@ -120,6 +123,8 @@ char *ipc_single_command(int socketfd, uint32_t type, const char *payload, uint3 | |||
120 | sway_abort("Unable to send IPC header"); | 123 | sway_abort("Unable to send IPC header"); |
121 | } | 124 | } |
122 | 125 | ||
126 | free(data); | ||
127 | |||
123 | if (write(socketfd, payload, *len) == -1) { | 128 | if (write(socketfd, payload, *len) == -1) { |
124 | sway_abort("Unable to send IPC payload"); | 129 | sway_abort("Unable to send IPC payload"); |
125 | } | 130 | } |
diff --git a/common/pango.c b/common/pango.c index 3bc97808..18b92e9d 100644 --- a/common/pango.c +++ b/common/pango.c | |||
@@ -87,11 +87,11 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, | |||
87 | 87 | ||
88 | void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, | 88 | void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, |
89 | int *baseline, double scale, bool markup, const char *fmt, ...) { | 89 | int *baseline, double scale, bool markup, const char *fmt, ...) { |
90 | char buf[max_chars]; | 90 | char *buf = malloc(sizeof(char) * max_chars); |
91 | 91 | ||
92 | va_list args; | 92 | va_list args; |
93 | va_start(args, fmt); | 93 | va_start(args, fmt); |
94 | if (vsnprintf(buf, sizeof(buf), fmt, args) >= max_chars) { | 94 | if (vsnprintf(buf, sizeof(char) * max_chars, fmt, args) >= max_chars) { |
95 | strcpy(&buf[sizeof(buf) - sizeof(overflow)], overflow); | 95 | strcpy(&buf[sizeof(buf) - sizeof(overflow)], overflow); |
96 | } | 96 | } |
97 | va_end(args); | 97 | va_end(args); |
@@ -103,15 +103,17 @@ void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, | |||
103 | *baseline = pango_layout_get_baseline(layout) / PANGO_SCALE; | 103 | *baseline = pango_layout_get_baseline(layout) / PANGO_SCALE; |
104 | } | 104 | } |
105 | g_object_unref(layout); | 105 | g_object_unref(layout); |
106 | |||
107 | free(buf); | ||
106 | } | 108 | } |
107 | 109 | ||
108 | void pango_printf(cairo_t *cairo, const char *font, | 110 | void pango_printf(cairo_t *cairo, const char *font, |
109 | double scale, bool markup, const char *fmt, ...) { | 111 | double scale, bool markup, const char *fmt, ...) { |
110 | char buf[max_chars]; | 112 | char *buf = malloc(sizeof(char) * max_chars); |
111 | 113 | ||
112 | va_list args; | 114 | va_list args; |
113 | va_start(args, fmt); | 115 | va_start(args, fmt); |
114 | if (vsnprintf(buf, sizeof(buf), fmt, args) >= max_chars) { | 116 | if (vsnprintf(buf, sizeof(char) * max_chars, fmt, args) >= max_chars) { |
115 | strcpy(&buf[sizeof(buf) - sizeof(overflow)], overflow); | 117 | strcpy(&buf[sizeof(buf) - sizeof(overflow)], overflow); |
116 | } | 118 | } |
117 | va_end(args); | 119 | va_end(args); |
@@ -124,4 +126,6 @@ void pango_printf(cairo_t *cairo, const char *font, | |||
124 | pango_cairo_update_layout(cairo, layout); | 126 | pango_cairo_update_layout(cairo, layout); |
125 | pango_cairo_show_layout(cairo, layout); | 127 | pango_cairo_show_layout(cairo, layout); |
126 | g_object_unref(layout); | 128 | g_object_unref(layout); |
129 | |||
130 | free(buf); | ||
127 | } | 131 | } |