Skip to content

Commit 5fae154

Browse files
committed
Merge pull request #125 from acv/leak-conf-c
Fix leaks in conf.c
2 parents 40deb49 + 25a975b commit 5fae154

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/conf.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ parse_auth_server(FILE *file, const char *filename, int *linenum)
301301

302302
switch (opcode) {
303303
case oAuthServHostname:
304+
/* Coverity rightfully pointed out we could have duplicates here. */
305+
if (NULL != host)
306+
free(host);
304307
host = safe_strdup(p2);
305308
break;
306309
case oAuthServPath:
@@ -351,8 +354,15 @@ parse_auth_server(FILE *file, const char *filename, int *linenum)
351354
}
352355

353356
/* only proceed if we have an host and a path */
354-
if (host == NULL)
357+
if (host == NULL) {
358+
free(path);
359+
free(authscriptpathfragment);
360+
free(pingscriptpathfragment);
361+
free(msgscriptpathfragment);
362+
free(portalscriptpathfragment);
363+
free(loginscriptpathfragment);
355364
return;
365+
}
356366

357367
debug(LOG_DEBUG, "Adding %s:%d (SSL: %d) %s to the auth server list",
358368
host, http_port, ssl_port, path);
@@ -850,6 +860,8 @@ void parse_trusted_mac_list(const char *ptr) {
850860
/* check for valid format */
851861
if (!check_mac_format(possiblemac)) {
852862
debug(LOG_ERR, "[%s] not a valid MAC address to trust. See option TrustedMACList in wifidog.conf for correct this mistake.", possiblemac);
863+
free(ptrcopy);
864+
free(mac);
853865
return;
854866
} else {
855867
if (sscanf(possiblemac, " %17[A-Fa-f0-9:]", mac) == 1) {
@@ -864,10 +876,10 @@ void parse_trusted_mac_list(const char *ptr) {
864876
} else {
865877
/* Advance to the last entry */
866878
for (p = config.trustedmaclist; p->next != NULL; p = p->next);
867-
p->next = safe_malloc(sizeof(t_trusted_mac));
868-
p = p->next;
869-
p->mac = safe_strdup(mac);
870-
p->next = NULL;
879+
p->next = safe_malloc(sizeof(t_trusted_mac));
880+
p = p->next;
881+
p->mac = safe_strdup(mac);
882+
p->next = NULL;
871883
}
872884
}
873885
}

0 commit comments

Comments
 (0)