Fix underflow in getFreeMemory()
author Albert Astals Cid
committer Albert Astals Cid
commit 5fb937a46aaf4e531ada816692b1e47fc95b20b0
tree 881c7d076df2d4ad154cd15199ff4012646bd3e9
parent 2a5257af50253500e47e8e701f1a7f3713c8237c
Fix underflow in getFreeMemory()

It actually serves three purposes:
a) Make sure all the values are there (this should be always true, but doesn't hurt making sure) because if SwapFree was there but SwapTotal was not, it'd be a mess
b) add up things in order so we don't underflow, currently the code did process stuff as it came in the file, and it happens that SwapTotal appears before SwapFree in /proc/meminfo so it actually did "MemFree:" + "Buffers:" + "Cached:" - "SwapTotal:" + "SwapFree:", which can underflow if "MemFree:" + "Buffers:" + "Cached:" < "SwapTotal:"
c) Do not underflow at all, so if "MemFree:" + "Buffers:" + "Cached:" + "SwapFree:" < "SwapTotal:" we return 0 correctly not a zillion of free memory

Aurélien you might want to update gwenviews copy of this code (there's a few other bugfixes we did a while ago you didn't update either)


BUGS: 291129
(cherry picked from commit 444e6b7b19bee5285f39a44007cf00f6e0b235d2)