diff mbox

Tell users about out-of-memory errors

Message ID 1264022195-20779-1-git-send-email-weil@mail.berlios.de
State New
Headers show

Commit Message

Stefan Weil Jan. 20, 2010, 9:16 p.m. UTC
Aborting without an error message when memory is short
is not helpful, so print the reason for the abort.

Try
	qemu -m 1000000
to force an out-of-memory error.

Signed-off-by: Stefan Weil <weil@mail.berlios.de>
---
 osdep.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

Comments

malc Jan. 20, 2010, 11:13 p.m. UTC | #1
On Wed, 20 Jan 2010, Stefan Weil wrote:

> Aborting without an error message when memory is short
> is not helpful, so print the reason for the abort.
> 
> Try
> 	qemu -m 1000000
> to force an out-of-memory error.

The patch is wrong for, at least, Windows.

> 
> Signed-off-by: Stefan Weil <weil@mail.berlios.de>
> ---
>  osdep.c |    6 +++++-
>  1 files changed, 5 insertions(+), 1 deletions(-)
> 
> diff --git a/osdep.c b/osdep.c
> index 1310684..5d4e810 100644
> --- a/osdep.c
> +++ b/osdep.c
> @@ -52,6 +52,7 @@
>  static void *oom_check(void *ptr)
>  {
>      if (ptr == NULL) {
> +        perror("qemu (memory allocation)");
>          abort();
>      }
>      return ptr;
> @@ -91,8 +92,11 @@ void *qemu_memalign(size_t alignment, size_t size)
>      int ret;
>      void *ptr;
>      ret = posix_memalign(&ptr, alignment, size);
> -    if (ret != 0)
> +    if (ret != 0) {
> +        fprintf(stderr, "Failed to allocate %zu B: %s\n",
> +                size, strerror(errno));
>          abort();
> +    }
>      return ptr;
>  #elif defined(CONFIG_BSD)
>      return oom_check(valloc(size));
>
diff mbox

Patch

diff --git a/osdep.c b/osdep.c
index 1310684..5d4e810 100644
--- a/osdep.c
+++ b/osdep.c
@@ -52,6 +52,7 @@ 
 static void *oom_check(void *ptr)
 {
     if (ptr == NULL) {
+        perror("qemu (memory allocation)");
         abort();
     }
     return ptr;
@@ -91,8 +92,11 @@  void *qemu_memalign(size_t alignment, size_t size)
     int ret;
     void *ptr;
     ret = posix_memalign(&ptr, alignment, size);
-    if (ret != 0)
+    if (ret != 0) {
+        fprintf(stderr, "Failed to allocate %zu B: %s\n",
+                size, strerror(errno));
         abort();
+    }
     return ptr;
 #elif defined(CONFIG_BSD)
     return oom_check(valloc(size));