O'Reilly logo

Hands-On System Programming with Linux by Kaiwan N Billimoria

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Test case 12

Memory leakage case 2 - leak more (in a loop). Quite often, the buggy leaking code might only be leaking a small amount of memory, a few bytes, by itself. The problem is, what if this leaky function is called in a loop hundreds, or perhaps, thousands of times, during process execution? Now the leakage is significant, and unfortunately, not immediately apparent.

To emulate precisely this and more, we execute two test cases (for Option 12):

  • We allocate, and leak, a tiny amount of memory (32 bytes) but in a loop 100,000 times (so, yes, we end up leaking over 3 MB)
  • We allocate, and leak, a large amount of memory (1 MB) in a loop 12 times (so, we end up leaking 12 MB).

Here's the relevant code:

[...]/* test case 12 : memory leak ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required