Skip to content
This repository has been archived by the owner on Dec 27, 2019. It is now read-only.

Commit

Permalink
ipc: make sure userspace communication frees wgdevice
Browse files Browse the repository at this point in the history
  • Loading branch information
zx2c4 committed Dec 2, 2019
1 parent f99a92c commit 88f34aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
23 changes: 13 additions & 10 deletions src/tools/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,12 @@ static int userspace_get_device(struct wgdevice **out, const char *iface)
return -errno;

f = userspace_interface_file(iface);
if (!f)
return -errno;
if (!f) {
ret = -errno;
free(dev);
*out = NULL;
return ret;
}

fprintf(f, "get=1\n\n");
fflush(f);
Expand All @@ -314,11 +318,8 @@ static int userspace_get_device(struct wgdevice **out, const char *iface)

while (getline(&key, &line_buffer_len, f) > 0) {
line_len = strlen(key);
if (line_len == 1 && key[0] == '\n') {
free(key);
fclose(f);
return ret;
}
if (line_len == 1 && key[0] == '\n')
goto err;
value = strchr(key, '=');
if (!value || line_len == 0 || key[line_len - 1] != '\n')
break;
Expand Down Expand Up @@ -382,7 +383,7 @@ static int userspace_get_device(struct wgdevice **out, const char *iface)
*end++ = '\0';
}
if (getaddrinfo(begin, end, &hints, &resolved) != 0) {
errno = ENETUNREACH;
ret = ENETUNREACH;
goto err;
}
if ((resolved->ai_family == AF_INET && resolved->ai_addrlen == sizeof(struct sockaddr_in)) ||
Expand Down Expand Up @@ -437,8 +438,10 @@ static int userspace_get_device(struct wgdevice **out, const char *iface)
ret = -EPROTO;
err:
free(key);
free_wgdevice(dev);
*out = NULL;
if (ret) {
free_wgdevice(dev);
*out = NULL;
}
fclose(f);
errno = -ret;
return ret;
Expand Down
4 changes: 3 additions & 1 deletion src/tools/setconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ static bool sync_conf(struct wgdevice *file)
return false;
}

if (!runtime->first_peer)
if (!runtime->first_peer) {
free_wgdevice(runtime);
return true;
}

file->flags &= ~WGDEVICE_REPLACE_PEERS;

Expand Down

0 comments on commit 88f34aa

Please sign in to comment.