From: Niklas Hofmann Date: Fri, 8 Aug 2014 10:40:17 +0000 (+0200) Subject: check result of malloc X-Git-Url: http://git.meshlink.io/?p=meshlink;a=commitdiff_plain;h=ad85858f2a2383af2cf0bcdede7de11dcf60aa8f check result of malloc --- diff --git a/src/discovery.c b/src/discovery.c index 7a7f1483..c004ce58 100644 --- a/src/discovery.c +++ b/src/discovery.c @@ -83,6 +83,13 @@ static void discovery_create_services(meshlink_handle_t *mesh) /* Create txt records */ size_t txt_name_len = sizeof(MESHLINK_MDNS_NAME_KEY) + 1 + strlen(mesh->name) + 1; txt_name = malloc(txt_name_len); + + if(txt_name == NULL) + { + fprintf(stderr, "Could not allocate memory for TXT record\n"); + goto fail; + } + snprintf(txt_name, txt_name_len, "%s=%s", MESHLINK_MDNS_NAME_KEY, mesh->name); char txt_fingerprint[sizeof(MESHLINK_MDNS_FINGERPRINT_KEY) + 1 + MESHLINK_FINGERPRINTLEN + 1]; @@ -117,7 +124,7 @@ fail: done: if(txt_name) - free(txt_name); + { free(txt_name); } } static void discovery_server_callback(AvahiServer *server, AvahiServerState state, void * userdata)