libpfctl: improve error handling

If we fail to open /dev/pf don't try to close it again. That would result in
errno getting overwritten by close(), hiding potentially useful information.

MFC after:	2 weeks
Sponsored by:	Rubicon Communications, LLC ("Netgate")
This commit is contained in:
Kristof Provost
2025-11-25 14:48:29 +01:00
parent 9562994a7a
commit 238ad591da
+2 -2
View File
@@ -76,7 +76,6 @@ pfctl_open(const char *pf_device)
struct pfctl_handle *h;
h = calloc(1, sizeof(struct pfctl_handle));
h->fd = -1;
h->fd = open(pf_device, O_RDWR);
if (h->fd < 0)
@@ -87,7 +86,8 @@ pfctl_open(const char *pf_device)
return (h);
error:
close(h->fd);
if (h->fd != -1)
close(h->fd);
snl_free(&h->ss);
free(h);