summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Franzen <fabian.franzen@tum.de>2017-04-12 13:11:34 +0200
committerFabian Franzen <fabian.franzen@tum.de>2017-04-12 13:11:34 +0200
commitad3fac03c34ddee7108542d292a09e99f879d3db (patch)
tree5cdf2b0e3d2db883172a0efedac6b4bcdbe2ae82
parentf45581f8d8bffff8f1eb98486953ec491eb77a05 (diff)
Fix memory leak/Use BEGINS_WITH macro
The orignal proposed code had a memory leak when returning true. Furthermore I included the handy BEGINS_WITH macro of i3 which makes the code (IMHO) a lot more readable.
-rw-r--r--src/first_network_device.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/first_network_device.c b/src/first_network_device.c
index abbc9b0..656e457 100644
--- a/src/first_network_device.c
+++ b/src/first_network_device.c
@@ -53,16 +53,16 @@ static bool sysfs_devtype(char *dest, size_t n, const char *ifnam) {
static bool is_virtual(const char *ifname) {
char path[1024];
char *target = NULL;
- const char virtual_template[] = "/sys/devices/virtual/";
+ bool is_virtual = false;
snprintf(path, sizeof(path), "/sys/class/net/%s", ifname);
if ((target = realpath(path, NULL))) {
- if (strncmp(virtual_template, target, strlen(virtual_template)) == 0)
- return true;
+ if (BEGINS_WITH(target, "/sys/devices/virtual/"))
+ is_virtual = true;
}
- free(target);
- return false;
+ free(target);
+ return is_virtual;
}
static net_type_t iface_type(const char *ifname) {