Make out-of-memory handling more uniform
This fixes one real bug in dumpstr().
* defs.h: Declare die_out_of_memory().
* strace.c (die_out_of_memory): New function.
(strace_popen): If allocation fails, call die_out_of_memory().
(main): Likewise.
(expand_tcbtab): Likewise.
(rebuild_pollv): Likewise.
* count.c (count_syscall): Likewise.
(call_summary_pers): Likewise.
* desc.c (decode_select): Likewise.
* file.c (sys_getdents): Likewise.
(sys_getdents64): Likewise.
(sys_getdirentries): Likewise.
* pathtrace.c (pathtrace_match): Likewise.
* syscall.c (qualify): Likewise.
* util.c (printstr): Likewise.
(dumpiov): Likewise.
(dumpstr): Likewise.
(fixvfork): Likewise.
* mem.c (sys_mincore): Don't check free() parameter for NULL.
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
diff --git a/file.c b/file.c
index c40fde2..09977e9 100644
--- a/file.c
+++ b/file.c
@@ -2422,11 +2422,8 @@
}
len = tcp->u_rval;
buf = len ? malloc(len) : NULL;
- if (len && !buf) {
- tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
- fprintf(stderr, "out of memory\n");
- return 0;
- }
+ if (len && !buf)
+ die_out_of_memory();
if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
free(buf);
@@ -2507,11 +2504,8 @@
}
len = tcp->u_rval;
buf = len ? malloc(len) : NULL;
- if (len && !buf) {
- tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
- fprintf(stderr, "out of memory\n");
- return 0;
- }
+ if (len && !buf)
+ die_out_of_memory();
if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
free(buf);
@@ -2581,11 +2575,8 @@
}
len = tcp->u_rval;
buf = malloc(len);
- if (buf == NULL) {
- tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
- fprintf(stderr, "out of memory\n");
- return 0;
- }
+ if (!buf)
+ die_out_of_memory();
if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
free(buf);