Copy data in msg callback 69/14669/1
authorOndrej Fabry <ofabry@cisco.com>
Wed, 5 Sep 2018 11:55:54 +0000 (13:55 +0200)
committerOndrej Fabry <ofabry@cisco.com>
Wed, 5 Sep 2018 11:55:54 +0000 (13:55 +0200)
Change-Id: I642b0f586a57101633982bcee5bad187a0749090
Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
core/request_handler.go

index 14c095d..c042948 100644 (file)
@@ -193,11 +193,12 @@ func (c *Connection) msgCallback(msgID uint16, data []byte) {
        // treat this as a last part of the reply
        lastReplyReceived := isMulti && msgID == c.pingReplyID
 
-       // send the data to the channel
+       // send the data to the channel, it needs to be copied,
+       // because it will be freed after this function returns
        sendReply(ch, &vppReply{
                msgID:        msgID,
                seqNum:       seqNum,
-               data:         data,
+               data:         append([]byte(nil), data...),
                lastReceived: lastReplyReceived,
        })