doc/coding-style.txt M8: Use g_try_malloc instead of g_malloc
---
src/dnsproxy.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/dnsproxy.c b/src/dnsproxy.c
index 48fbef0..9be2918 100644
--- a/src/dnsproxy.c
+++ b/src/dnsproxy.c
@@ -1437,7 +1437,11 @@ static int cache_update(struct server_data *srv, unsigned char
*msg,
if (srv->protocol == IPPROTO_UDP)
cache_offset = 2;
data->data_len = msg_len + cache_offset;
- data->data = ptr = g_malloc(data->data_len);
+ data->data = ptr = g_try_malloc(data->data_len);
+ if (!ptr) {
+ g_free(data);
+ return -ENOMEM;
+ }
ptr[0] = (data->data_len - 2) / 256;
ptr[1] = (data->data_len - 2) - ptr[0] * 256;
if (srv->protocol == IPPROTO_UDP)
@@ -3486,7 +3490,12 @@ static bool udp_listener_event(GIOChannel *channel, GIOCondition
condition,
}
req->name = g_strdup(query);
- req->request = g_malloc(len);
+ req->request = g_try_malloc(len);
+ if (req->request) {
+ g_free(req);
+ return true;
+ }
+
memcpy(req->request, buf, len);
req->timeout = g_timeout_add_seconds(5, request_timeout, req);
request_list = g_slist_append(request_list, req);
--
1.9.1