The branch main has been updated by kp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=238ad591da9eede122a708be925b6b6a20e9046b

commit 238ad591da9eede122a708be925b6b6a20e9046b
Author:     Kristof Provost <[email protected]>
AuthorDate: 2025-11-25 13:48:29 +0000
Commit:     Kristof Provost <[email protected]>
CommitDate: 2025-11-25 13:50:09 +0000

    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")
---
 lib/libpfctl/libpfctl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/libpfctl/libpfctl.c b/lib/libpfctl/libpfctl.c
index e747763ae6ef..3db596d6fd38 100644
--- a/lib/libpfctl/libpfctl.c
+++ b/lib/libpfctl/libpfctl.c
@@ -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);
 

Reply via email to