Fix memory leak in GetFullyQualifiedName()

This commit is contained in:
Andrew Schwartzmeyer committed 2016-09-12 15:01:18 -07:00
1 parent e1bfe97d87
commit b86b1f870a
1 file changed
+6 -5
@@ -43,17 +43,18 @@ char *GetFullyQualifiedName()
* POSIX compliant, and some are being deprecated. getaddrinfo seems * POSIX compliant, and some are being deprecated. getaddrinfo seems
* to be the best choice. * to be the best choice.
*/ */
char *fullName = NULL;
if (getaddrinfo(computerName, "http", &hints, &info) != 0) if (getaddrinfo(computerName, "http", &hints, &info) != 0)
{ {
errno = ERROR_BAD_NET_NAME; goto exit;
return NULL;
} }
// info is actually a link-list. We'll just return the first full name // return the first canonical name in the list
fullName = strndup(info->ai_canonname, strlen(info->ai_canonname));
char *fullName = strndup(info->ai_canonname, strlen(info->ai_canonname));
// only free info if getaddrinfo was successful
freeaddrinfo(info); freeaddrinfo(info);
exit:
free(computerName); free(computerName);
return fullName; return fullName;
} }