From cfd364b011e170377ae002551c4391c01f51acbf Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 20 Aug 2011 13:41:13 +0200 Subject: [PATCH] Small optimizations related to memory allocation * strace (expand_tcbtab): Shorten "out of memory" message. (rebuild_pollv): Remove unnecessary NULL check before free(). * util.c (dumpstr): Add a comment about likely bug. Signed-off-by: Denys Vlasenko --- strace.c | 7 +++---- util.c | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/strace.c b/strace.c index 84bcddb1..127275c0 100644 --- a/strace.c +++ b/strace.c @@ -1233,7 +1233,7 @@ expand_tcbtab(void) struct tcb *newtcbs = calloc(tcbtabsize, sizeof(newtcbs[0])); struct tcb **newtab = realloc(tcbtab, tcbtabsize * 2 * sizeof(tcbtab[0])); if (newtab == NULL || newtcbs == NULL) - error_msg_and_die("expand_tcbtab: out of memory"); + error_msg_and_die("Out of memory"); tcbtabsize *= 2; tcbtab = newtab; while (i < tcbtabsize) @@ -1854,9 +1854,8 @@ rebuild_pollv(void) { int i, j; - if (pollv != NULL) - free(pollv); - pollv = (struct pollfd *) malloc(nprocs * sizeof pollv[0]); + free(pollv); + pollv = malloc(nprocs * sizeof(pollv[0])); if (pollv == NULL) { error_msg_and_die("Out of memory"); } diff --git a/util.c b/util.c index 9ccc5c93..ec0b3cbc 100644 --- a/util.c +++ b/util.c @@ -691,6 +691,7 @@ dumpstr(struct tcb *tcp, long addr, int len) str = malloc(len); if (str == NULL) { fprintf(stderr, "out of memory\n"); + /* BUG! On next call we may use NULL str! */ return; } strsize = len; -- 2.40.0