fix use after free

This commit is contained in:
Freya Murphy 2023-12-14 13:02:30 -05:00 committed by trimill
parent b2ca9fb81a
commit e065c4f8ef
No known key found for this signature in database
GPG key ID: 5FCAB0BC7C851657

View file

@ -1,4 +1,5 @@
#include <arpa/inet.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <stdint.h>
@ -54,8 +55,9 @@ int tel_get_addr(char *ip, char *port, struct sockaddr **addr, socklen_t *addr_l
int res = getaddrinfo(ip, port, &hints, &info);
if(res != 0) return res;
*addr = info->ai_addr;
*addr = malloc(info->ai_addrlen);
*addr_len = info->ai_addrlen;
memcpy(*addr, info->ai_addr, info->ai_addrlen);
freeaddrinfo(info);
return 0;