Tell users about out-of-memory errors
PATCH 1/1 Tell users about out-of-memory errors
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.
--- osdep.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
osdep.c +5 -1
@@ -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));
Signature · 1 line
1.6.5
Quoted 6 lines · Stefan Weil
Aborting without an error message when memory is short is not helpful, so print the reason for the abort.
Try
qemu -m 1000000to force an out-of-memory error.
The patch is wrong for, at least, Windows.
Quoted 32 lines
Signed-off-by Stefan Weil <[email protected]>--- osdep.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)osdep.c +5
-1@@ -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));
Signature · 1 line
mailto:[email protected]
PATCH 1/1 Tell users about out-of-memory errors
Aborting without an error message when memory is short is not helpful, so print the reason for the abort.
Try
qemu -m 1000000 or qemu -m 2000 (win32)
to force an out-of-memory error.
v2:
* Fix error message for win32.
* Fix error message for posix_memalign.
Thanks to malc for the hints.
--- osdep.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-)
osdep.c +9 -1
@@ -52,6 +52,11 @@static void *oom_check (void *ptr) {if (ptr ==NULL ) { +#if defined(_WIN32) +fprintf (stderr,"Failed to allocate memory: %lu\n" ,GetLastError ()); +#else +fprintf (stderr,"Failed to allocate memory: %s\n" ,strerror (errno)); +#endif abort (); }return ptr;
@@ -91,8 +96,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 (ret));abort (); + }return ptr;#elif defined(CONFIG_BSD )return oom_check (valloc (size));
Signature · 1 line
1.6.5
Anthony Liguori
AppliedQuoted 10 lines · Stefan Weil
Aborting without an error message when memory is short is not helpful, so print the reason for the abort.
Try
qemu -m 1000000 or qemu -m 2000 (win32)to force an out-of-memory error.
Quoted 8 lines
v2:
* Fix error message for win32.
* Fix error message forposix_memalign.Thanks to malc for the hints.
Signed-off-by Stefan Weil<[email protected]>
Applied. Thanks.
Regards,
Anthony Liguori
Quoted 34 lines
--- osdep.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-)osdep.c +9
-1@@ -52,6 +52,11 @@static void *oom_check (void *ptr) {if (ptr ==NULL ) { +#if defined(_WIN32) +fprintf (stderr,"Failed to allocate memory: %lu\n" ,GetLastError ()); +#else +fprintf (stderr,"Failed to allocate memory: %s\n" ,strerror (errno)); +#endif abort (); }return ptr;@@ -91,8 +96,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 (ret));abort (); + }return ptr;#elif defined(CONFIG_BSD )return oom_check (valloc (size));