Fix a few memory leaks in the CLI found by AddressSanitizer.
This commit is contained in:
parent
543c0abbd9
commit
7306823843
1 changed files with 15 additions and 8 deletions
|
@ -417,6 +417,7 @@ static bool ed25519_keygen(bool ask) {
|
||||||
|
|
||||||
char *pubkey = ecdsa_get_base64_public_key(key);
|
char *pubkey = ecdsa_get_base64_public_key(key);
|
||||||
fprintf(f, "Ed25519PublicKey = %s\n", pubkey);
|
fprintf(f, "Ed25519PublicKey = %s\n", pubkey);
|
||||||
|
free(pubkey);
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
ecdsa_free(key);
|
ecdsa_free(key);
|
||||||
|
@ -1804,7 +1805,7 @@ static int cmd_config(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool try_bind(int port) {
|
static bool try_bind(int port) {
|
||||||
struct addrinfo *ai = NULL;
|
struct addrinfo *ai = NULL, *aip;
|
||||||
struct addrinfo hint = {
|
struct addrinfo hint = {
|
||||||
.ai_flags = AI_PASSIVE,
|
.ai_flags = AI_PASSIVE,
|
||||||
.ai_family = AF_UNSPEC,
|
.ai_family = AF_UNSPEC,
|
||||||
|
@ -1812,24 +1813,30 @@ static bool try_bind(int port) {
|
||||||
.ai_protocol = IPPROTO_TCP,
|
.ai_protocol = IPPROTO_TCP,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool success = true;
|
||||||
char portstr[16];
|
char portstr[16];
|
||||||
snprintf(portstr, sizeof portstr, "%d", port);
|
snprintf(portstr, sizeof portstr, "%d", port);
|
||||||
|
|
||||||
if(getaddrinfo(NULL, portstr, &hint, &ai) || !ai)
|
if(getaddrinfo(NULL, portstr, &hint, &ai) || !ai)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
while(ai) {
|
for(aip = ai; aip; aip = aip->ai_next) {
|
||||||
int fd = socket(ai->ai_family, SOCK_STREAM, IPPROTO_TCP);
|
int fd = socket(ai->ai_family, SOCK_STREAM, IPPROTO_TCP);
|
||||||
if(!fd)
|
if(!fd) {
|
||||||
return false;
|
success = false;
|
||||||
int result = bind(fd, ai->ai_addr, ai->ai_addrlen);
|
break;
|
||||||
closesocket(fd);
|
|
||||||
if(result)
|
|
||||||
return false;
|
|
||||||
ai = ai->ai_next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
int result = bind(fd, ai->ai_addr, ai->ai_addrlen);
|
||||||
|
closesocket(fd);
|
||||||
|
if(result) {
|
||||||
|
success = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
freeaddrinfo(ai);
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
int check_port(char *name) {
|
int check_port(char *name) {
|
||||||
|
|
Loading…
Reference in a new issue