aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-12-02 19:19:38 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2019-12-02 19:19:38 +0100
commit88f34aa88759661b87e62cebb013229f3767a11d (patch)
tree9ea605b043f8c8efae4bb13a47b67b341d418198
parentsend: avoid touching skb->{next,prev} directly (diff)
downloadWireGuard-88f34aa88759661b87e62cebb013229f3767a11d.tar.xz
WireGuard-88f34aa88759661b87e62cebb013229f3767a11d.zip
ipc: make sure userspace communication frees wgdevice
-rw-r--r--src/tools/ipc.c23
-rw-r--r--src/tools/setconf.c4
2 files changed, 16 insertions, 11 deletions
diff --git a/src/tools/ipc.c b/src/tools/ipc.c
index 89484b1..7207efc 100644
--- a/src/tools/ipc.c
+++ b/src/tools/ipc.c
@@ -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);
@@ -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;
@@ -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)) ||
@@ -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;
diff --git a/src/tools/setconf.c b/src/tools/setconf.c
index a244c07..f778f40 100644
--- a/src/tools/setconf.c
+++ b/src/tools/setconf.c
@@ -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;