mirror of
https://github.com/NLnetLabs/unbound.git
synced 2026-08-17 21:25:50 +02:00
authzone: fix memory leak in xfer_set_masters() error path (#1480)
Added memory deallocation for the `file` and `host` fields of the `auth_master` node in the event of a URL/allocation error, and unlinked the partially created node from the masters list by resetting the link that pointed to it. Signed-off-by: Petr Vaganov <petrvaganoff@gmail.com>
This commit is contained in:
+14
-1
@@ -7596,35 +7596,48 @@ xfer_set_masters(struct auth_master** list, struct config_auth* c,
|
|||||||
{
|
{
|
||||||
struct auth_master* m;
|
struct auth_master* m;
|
||||||
struct config_strlist* p;
|
struct config_strlist* p;
|
||||||
|
struct auth_master** tail;
|
||||||
/* list points to the first, or next pointer for the new element */
|
/* list points to the first, or next pointer for the new element */
|
||||||
while(*list) {
|
while(*list) {
|
||||||
list = &( (*list)->next );
|
list = &( (*list)->next );
|
||||||
}
|
}
|
||||||
if(with_http)
|
if(with_http)
|
||||||
for(p = c->urls; p; p = p->next) {
|
for(p = c->urls; p; p = p->next) {
|
||||||
|
tail = list;
|
||||||
m = auth_master_new(&list);
|
m = auth_master_new(&list);
|
||||||
if(!m) return 0;
|
if(!m) return 0;
|
||||||
m->http = 1;
|
m->http = 1;
|
||||||
if(!parse_url(p->str, &m->host, &m->file, &m->port, &m->ssl))
|
if(!parse_url(p->str, &m->host, &m->file, &m->port, &m->ssl)) {
|
||||||
|
free(m->host);
|
||||||
|
free(m->file);
|
||||||
|
free(m);
|
||||||
|
*tail = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for(p = c->masters; p; p = p->next) {
|
for(p = c->masters; p; p = p->next) {
|
||||||
|
tail = list;
|
||||||
m = auth_master_new(&list);
|
m = auth_master_new(&list);
|
||||||
if(!m) return 0;
|
if(!m) return 0;
|
||||||
m->ixfr = 1; /* this flag is not configurable */
|
m->ixfr = 1; /* this flag is not configurable */
|
||||||
m->host = strdup(p->str);
|
m->host = strdup(p->str);
|
||||||
if(!m->host) {
|
if(!m->host) {
|
||||||
log_err("malloc failure");
|
log_err("malloc failure");
|
||||||
|
free(m);
|
||||||
|
*tail = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(p = c->allow_notify; p; p = p->next) {
|
for(p = c->allow_notify; p; p = p->next) {
|
||||||
|
tail = list;
|
||||||
m = auth_master_new(&list);
|
m = auth_master_new(&list);
|
||||||
if(!m) return 0;
|
if(!m) return 0;
|
||||||
m->allow_notify = 1;
|
m->allow_notify = 1;
|
||||||
m->host = strdup(p->str);
|
m->host = strdup(p->str);
|
||||||
if(!m->host) {
|
if(!m->host) {
|
||||||
log_err("malloc failure");
|
log_err("malloc failure");
|
||||||
|
free(m);
|
||||||
|
*tail = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user