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>
This commit is contained in:
Denys Vlasenko 2011-08-20 13:41:13 +02:00
parent 5d64581e10
commit cfd364b011
2 changed files with 4 additions and 4 deletions

View File

@ -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");
}

1
util.c
View File

@ -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;