fuwaneko / node-protobuf

Google Protocol Buffers wrapper for Node.js [UNMAINTAINED]
181 stars 42 forks source link

Crash after multiple parsing #53

Closed pnagy closed 8 years ago

pnagy commented 8 years ago

I found a very interesting issue in your package. I have a sample proto file:

package test.schema;

message msg {
    required string StringValue = 1;
}

message msg2 {
    required string StringValue = 1;
    optional bytes Bytes = 2;
}

I also have the following script:

var fs = require('fs');
var protobuf = require('node-protobuf');

protocol =  new protobuf(fs.readFileSync(__dirname + '/protocol.desc'));

message = protocol.serialize({StringValue: "string"}, "test.schema.msg2");

c = 0;
setInterval(function () {
    console.log("Parsing message... ", ++c);
    console.log(protocol.parse(message, "test.schema.msg2"));
}, 100);

I would expect that this script does its job and keeps parsing the message without any error. Unfortunately after the 167th iteration it crashes with the following message:

node(7822,0x7fff7a1e0000) malloc: *** error for object 0x7fff5fbfed41: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6

If I change the message type to msg it can survive more than 3000 iteration (I killed it after that :) ) Of course this is a minimal script to show the problem. We expereinced this issue in a way bigger project where this error was thrown after the first parsing. Env: Node v4.2.1 node-protobuf >= v1.2.8 protobuf v2.6

I tried it out with node v0.12 and node-protobuf v1.2.7 and it was totally ok.