aboutsummaryrefslogtreecommitdiffstats
path: root/components/swap.c
diff options
context:
space:
mode:
authordrkhsh <me@drkhsh.at>2026-06-23 18:42:19 +0200
committerdrkhsh <me@drkhsh.at>2026-06-24 00:11:32 +0200
commit7a8545952ef647e6862c5b184aee0b13a48e741d (patch)
treee04f497b4016b041211936a7aa6f1bd919bc764b /components/swap.c
parent614c275b42064c5433fbb086e7d9639a19f1f127 (diff)
downloadslstatus-7a8545952ef647e6862c5b184aee0b13a48e741d.tar.gz
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 (limited to 'components/swap.c')
-rw-r--r--components/swap.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/components/swap.c b/components/swap.c
index f270d93..dbd2747 100644
--- 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);