From 468d937c8f85ff7e7c313a4444e4f47932df0b26 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Sun, 26 Aug 2012 22:29:48 +0200 Subject: [PATCH] much stricter memory allocation for msg Only allocate what you need=+1 (just to be sure) --- msg.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/msg.go b/msg.go index 0ad77108..34d460e2 100644 --- a/msg.go +++ b/msg.go @@ -1210,7 +1210,7 @@ func (dns *Msg) Pack() (msg []byte, ok bool) { dh.Arcount = uint16(len(extra)) // TODO(mg): still a little too much, but better than 64K... - msg = make([]byte, dns.Len()*2) + msg = make([]byte, dns.Len()+1) // Pack it in: header and then the pieces. off := 0 @@ -1230,6 +1230,7 @@ func (dns *Msg) Pack() (msg []byte, ok bool) { if !ok { return nil, false } + //println("allocated", dns.Len()+1, "used", off) return msg[:off], true }