Browse Source

Re-add memset() that seemed redundant but is necessary in case of GC.

Joshua Haberman 6 năm trước cách đây
mục cha
commit
3e3407af49

+ 3 - 0
ruby/ext/google/protobuf_c/message.c

@@ -70,6 +70,9 @@ VALUE Message_alloc(VALUE klass) {
   msg = (MessageHeader*)ALLOC_N(uint8_t,
   msg = (MessageHeader*)ALLOC_N(uint8_t,
                                 sizeof(MessageHeader) + desc->layout->size);
                                 sizeof(MessageHeader) + desc->layout->size);
 
 
+  // Required in case a GC happens before layout_init().
+  memset(msg, 0, desc->layout->size);
+
   // We wrap first so that everything in the message object is GC-rooted in case
   // We wrap first so that everything in the message object is GC-rooted in case
   // a collection happens during object creation in layout_init().
   // a collection happens during object creation in layout_init().
   ret = TypedData_Wrap_Struct(klass, &Message_type, msg);
   ret = TypedData_Wrap_Struct(klass, &Message_type, msg);