Browse Source

Must not call hex.Dump in non-debug mode...

Jakob Borg 10 years ago
parent
commit
e3c0fba34b
2 changed files with 10 additions and 4 deletions
  1. 4 0
      lib/protocol/debug.go
  2. 6 4
      lib/protocol/protocol.go

+ 4 - 0
lib/protocol/debug.go

@@ -16,3 +16,7 @@ var (
 func init() {
 	l.SetDebug("protocol", strings.Contains(os.Getenv("STTRACE"), "protocol") || os.Getenv("STTRACE") == "all")
 }
+
+func shouldDebug() bool {
+	return l.ShouldDebug("protocol")
+}

+ 6 - 4
lib/protocol/protocol.go

@@ -411,10 +411,12 @@ func (c *rawConnection) readMessage() (hdr header, msg encodable, err error) {
 		l.Debugf("decompressed to %d bytes", len(msgBuf))
 	}
 
-	if len(msgBuf) > 1024 {
-		l.Debugf("message data:\n%s", hex.Dump(msgBuf[:1024]))
-	} else {
-		l.Debugf("message data:\n%s", hex.Dump(msgBuf))
+	if shouldDebug() {
+		if len(msgBuf) > 1024 {
+			l.Debugf("message data:\n%s", hex.Dump(msgBuf[:1024]))
+		} else {
+			l.Debugf("message data:\n%s", hex.Dump(msgBuf))
+		}
 	}
 
 	// We check each returned error for the XDRError.IsEOF() method.