minicom/memleaks_term_socket_connect_tcp.patch
Pavol Žáčik 9cb0bab097
Fix issues found by static analysis
One patch fixes memory leaks, the other
fixes an issue where a function returns
a pointer to its local array.

Resolves: RHEL-39982
Resolves: RHEL-35668
2024-08-15 11:40:11 +02:00

31 lines
712 B
Diff

diff --git a/src/main.c b/src/main.c
index f5f65e1..8767032 100644
--- a/src/main.c
+++ b/src/main.c
@@ -190,6 +190,7 @@ static void term_socket_connect_tcp(void)
char *s_port = strchr(s_addr, ':');
if (!s_port) {
fprintf(stderr, "No port given\n");
+ free(s);
return;
}
*s_port = 0;
@@ -202,6 +203,7 @@ static void term_socket_connect_tcp(void)
int r = getaddrinfo(s_addr, s_port, &hints, &result);
if (r) {
fprintf(stderr, "Name resolution failed: %s\n", gai_strerror(r));
+ free(s);
return;
}
@@ -221,8 +223,7 @@ static void term_socket_connect_tcp(void)
term_socket_close();
}
- if (rp)
- freeaddrinfo(result);
+ freeaddrinfo(result);
}
/*