From: Denys Vlasenko <dvlasenk@redhat.com>
Date: Sat, 20 Aug 2011 11:41:13 +0000 (+0200)
Subject: Small optimizations related to memory allocation
X-Git-Tag: v4.7~312
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cfd364b011e170377ae002551c4391c01f51acbf;p=strace

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 <dvlasenk@redhat.com>
---

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;