URI:
       openbsd swap: advance iterator, fix leaks - slstatus - status monitor
  HTML git clone git://git.suckless.org/slstatus
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit 7a8545952ef647e6862c5b184aee0b13a48e741d
   DIR parent 614c275b42064c5433fbb086e7d9639a19f1f127
  HTML Author: drkhsh <me@drkhsh.at>
       Date:   Tue, 23 Jun 2026 18:42:19 +0200
       
       openbsd swap: advance iterator, fix leaks
       
       the swap entry loop read the first entry repeatedly instead of
       iterating with sep[i]. also free the allocation on error paths
       and fix "SWAP_STATA" typo in the warning message.
       
       Diffstat:
         M components/swap.c                   |      10 ++++++----
       
       1 file changed, 6 insertions(+), 4 deletions(-)
       ---
   DIR diff --git a/components/swap.c b/components/swap.c
       @@ -112,7 +112,7 @@
                        int rnswap, nswap, i;
        
                        if ((nswap = swapctl(SWAP_NSWAP, 0, 0)) < 1) {
       -                        warn("swaptctl 'SWAP_NSWAP':");
       +                        warn("swapctl 'SWAP_NSWAP':");
                                return 1;
                        }
                        if (!(fsep = sep = calloc(nswap, sizeof(*sep)))) {
       @@ -120,11 +120,13 @@
                                return 1;
                        }
                        if ((rnswap = swapctl(SWAP_STATS, (void *)sep, nswap)) < 0) {
       -                        warn("swapctl 'SWAP_STATA':");
       +                        warn("swapctl 'SWAP_STATS':");
       +                        free(fsep);
                                return 1;
                        }
                        if (nswap != rnswap) {
                                warn("getstats: SWAP_STATS != SWAP_NSWAP");
       +                        free(fsep);
                                return 1;
                        }
        
       @@ -132,8 +134,8 @@
                        *used = 0;
        
                        for (i = 0; i < rnswap; i++) {
       -                        *total += sep->se_nblks >> 1;
       -                        *used += sep->se_inuse >> 1;
       +                        *total += sep[i].se_nblks >> 1;
       +                        *used += sep[i].se_inuse >> 1;
                        }
        
                        free(fsep);