]> granicus.if.org Git - strace/commitdiff
Small optimizations related to memory allocation
authorDenys Vlasenko <dvlasenk@redhat.com>
Sat, 20 Aug 2011 11:41:13 +0000 (13:41 +0200)
committerDenys Vlasenko <dvlasenk@redhat.com>
Tue, 23 Aug 2011 10:53:01 +0000 (12:53 +0200)
* 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>
strace.c
util.c

index 84bcddb1ed8579daed048aab94100f80dbbf6234..127275c0b3a1941bddcb9d3e592be65dff34c237 100644 (file)
--- 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 9ccc5c9303ae9e74fbacd6207e4e89cd71e61992..ec0b3cbc7fff688fbc40167f17f5907ad5ee0f6e 100644 (file)
--- 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;