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:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user