Looked at a leak mentioned on IRC and saw a large amount of waste...
This looks easy and safe to avoid:

>From b5550f22ceefb0941198810370c9ed1c04301992 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[email protected]>
Date: Tue, 21 Apr 2009 21:25:48 +0200
Subject: [PATCH] perf: avoid writing 1MB of zero bytes

Don't initialize the entire just-allocated buffer to all zeroes.
The very next lines initialize all members except "data".
* exec/totempg.c (assembly_ref): Initialize the first byte of
assembly->data to 0, just in case someone uses it as a string.
---
 exec/totempg.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/exec/totempg.c b/exec/totempg.c
index 2d97e68..47f8413 100644
--- a/exec/totempg.c
+++ b/exec/totempg.c
@@ -283,12 +283,12 @@ static struct assembly *assembly_ref (unsigned int nodeid)
         * Nothing available in inuse or free list, so allocate a new one
         */
        assembly = malloc (sizeof (struct assembly));
-       memset (assembly, 0, sizeof (struct assembly));
        /*
         * TODO handle memory allocation failure here
         */
        assert (assembly);
        assembly->nodeid = nodeid;
+       assembly->data[0] = 0;
        assembly->index = 0;
        assembly->last_frag_num = 0;
        assembly->throw_away_mode = THROW_AWAY_INACTIVE;
--
1.6.3.rc1.205.g37f8
_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais

Reply via email to