Skip to content

Commit 1133cb6

Browse files
committed
Swap (OpenBSD): fix mem leaks
1 parent a091d20 commit 1133cb6

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/detection/swap/swap_obsd.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,24 @@ const char* ffDetectSwap(FFSwapResult* swap)
1010
{
1111
int nswap = swapctl(SWAP_NSWAP, 0, 0);
1212
if (nswap < 0) return "swapctl(SWAP_NSWAP) failed";
13-
if (nswap == 0) NULL;
13+
if (nswap == 0) return NULL;
1414

15-
struct swapent* swdev = malloc((uint32_t) nswap * sizeof(*swdev));
15+
FF_AUTO_FREE struct swapent* swdev = malloc((uint32_t) nswap * sizeof(*swdev));
1616

1717
if (swapctl(SWAP_STATS, swdev, nswap) < 0)
1818
return "swapctl(SWAP_STATS) failed";
1919

20+
uint64_t swapTotal = 0, swapUsed = 0;
2021
for (int i = 0; i < nswap; i++)
2122
{
2223
if (swdev[i].se_flags & SWF_ENABLE)
2324
{
24-
swap->bytesUsed += (uint64_t) swdev[i].se_inuse * DEV_BSIZE;
25-
swap->bytesTotal += (uint64_t) swdev[i].se_nblks * DEV_BSIZE;
25+
swapUsed += (uint64_t) swdev[i].se_inuse;
26+
swapTotal += (uint64_t) swdev[i].se_nblks;
2627
}
2728
}
29+
swap->bytesUsed = swapUsed * DEV_BSIZE;
30+
swap->bytesTotal = swapTotal * DEV_BSIZE;
2831

2932
return NULL;
3033
}

0 commit comments

Comments
 (0)