File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed
Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments