From c39c0c22ac072e933cb8f9fdc518aafdb4ba49d3 Mon Sep 17 00:00:00 2001 From: hjp Date: Tue, 5 Jul 2016 18:20:45 +0000 Subject: [PATCH] Print allocated memory --- hogs/memhog.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hogs/memhog.c b/hogs/memhog.c index 03cf6b6..90a29a7 100644 --- a/hogs/memhog.c +++ b/hogs/memhog.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -8,6 +9,7 @@ int main(void) { while (s) { void *p; + errno = 0; if (p = malloc(s)) { sum += s; printf("%lu - %lu\n", @@ -17,6 +19,11 @@ int main(void) { memset(p, 'a', s); s *= 2; } else { + printf("%lu - %lu: %s\n", + (unsigned long)s, + (unsigned long)sum, + strerror(errno) + ); s /= 2; } }