mini_racer 0.2.10 → 0.2.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a50c6aea93635efc351ce95def252df6edb3fbede6a0372272f8c9cd58f9aaed
4
- data.tar.gz: b01cd6a98eca13db18d539ed259e4acd968eb073582979ff06f78a5df54a4207
3
+ metadata.gz: 276af6ac1a39ed9f00576b34e1944c0c27c9ee745871fc50de8010f06c642abf
4
+ data.tar.gz: 911e1bf55677699df6623afec3430be7eccba88664c60e085562fb37e5a62847
5
5
  SHA512:
6
- metadata.gz: cac0258ac9f1f93245b00b313d004504d770e9dce3eb5ac9a8d547a1b24cd3649ec9039d9c7429ff7871f9f8d3c07e260997d86647905ba433688f361bd72611
7
- data.tar.gz: b054a38013e7bcffe689c3732d7d95abbaf61c350dab275ff7e04e667bc5f15ae9863a706beb2848681b8d69cc1194c0bb87014a4c49e2f49d14a4289b1f6436
6
+ metadata.gz: 17494a1abe347480cd62671155bcde45e60c8d47fee115338606a2b793308d9fe06f756da795f2b4fc84bbf8fded92ec6f6c3a656164ba195298efc4f27144e3
7
+ data.tar.gz: 0c9cc0bad0cf4963582c00d4a6ac8df547fb1b655464f01ae115ec286c864c364521bba5d70ed2081c589d007328151af34e001ad48280f18d9afeca0af879c4
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ - 14-05-2020
2
+
3
+ - 0.2.11
4
+
5
+ - FIX: dumping heap snapshots was not flushing the file leading to corrupt snapshots
6
+ - FIX: a use-after-free shutdown crash
7
+
1
8
  - 0.2.10
2
9
 
3
10
  - 22-04-2020
@@ -156,6 +156,10 @@ static VALUE rb_cDateTime = Qnil;
156
156
  static std::unique_ptr<Platform> current_platform = NULL;
157
157
  static std::mutex platform_lock;
158
158
 
159
+ static pthread_attr_t *thread_attr_p;
160
+ static pthread_rwlock_t exit_lock = PTHREAD_RWLOCK_INITIALIZER;
161
+ static bool ruby_exiting; // guarded by exit_lock
162
+
159
163
  static VALUE rb_platform_set_flag_as_str(VALUE _klass, VALUE flag_as_str) {
160
164
  bool platform_already_initialized = false;
161
165
 
@@ -1205,7 +1209,7 @@ void free_isolate(IsolateInfo* isolate_info) {
1205
1209
  delete isolate_info->allocator;
1206
1210
  }
1207
1211
 
1208
- static void *free_context_raw(void* arg) {
1212
+ static void free_context_raw(void *arg) {
1209
1213
  ContextInfo* context_info = (ContextInfo*)arg;
1210
1214
  IsolateInfo* isolate_info = context_info->isolate_info;
1211
1215
  Persistent<Context>* context = context_info->context;
@@ -1222,6 +1226,20 @@ static void *free_context_raw(void* arg) {
1222
1226
  }
1223
1227
 
1224
1228
  xfree(context_info);
1229
+ }
1230
+
1231
+ static void *free_context_thr(void* arg) {
1232
+ if (pthread_rwlock_tryrdlock(&exit_lock) != 0) {
1233
+ return NULL;
1234
+ }
1235
+ if (ruby_exiting) {
1236
+ return NULL;
1237
+ }
1238
+
1239
+ free_context_raw(arg);
1240
+
1241
+ pthread_rwlock_unlock(&exit_lock);
1242
+
1225
1243
  return NULL;
1226
1244
  }
1227
1245
 
@@ -1235,22 +1253,17 @@ static void free_context(ContextInfo* context_info) {
1235
1253
  context_info_copy->context = context_info->context;
1236
1254
 
1237
1255
  if (isolate_info && isolate_info->refs() > 1) {
1238
- pthread_t free_context_thread;
1239
- if (pthread_create(&free_context_thread, NULL, free_context_raw, (void*)context_info_copy)) {
1240
- fprintf(stderr, "WARNING failed to release memory in MiniRacer, thread to release could not be created, process will leak memory\n");
1241
- }
1242
-
1256
+ pthread_t free_context_thread;
1257
+ if (pthread_create(&free_context_thread, thread_attr_p,
1258
+ free_context_thr, (void*)context_info_copy)) {
1259
+ fprintf(stderr, "WARNING failed to release memory in MiniRacer, thread to release could not be created, process will leak memory\n");
1260
+ }
1243
1261
  } else {
1244
1262
  free_context_raw(context_info_copy);
1245
1263
  }
1246
1264
 
1247
- if (context_info->context && isolate_info && isolate_info->isolate) {
1248
- context_info->context = NULL;
1249
- }
1250
-
1251
- if (isolate_info) {
1252
- context_info->isolate_info = NULL;
1253
- }
1265
+ context_info->context = NULL;
1266
+ context_info->isolate_info = NULL;
1254
1267
  }
1255
1268
 
1256
1269
  static void deallocate_isolate(void* data) {
@@ -1408,6 +1421,8 @@ rb_heap_snapshot(VALUE self, VALUE file) {
1408
1421
  FileOutputStream stream(fp);
1409
1422
  snap->Serialize(&stream, HeapSnapshot::kJSON);
1410
1423
 
1424
+ fflush(fp);
1425
+
1411
1426
  const_cast<HeapSnapshot*>(snap)->Delete();
1412
1427
 
1413
1428
  return Qtrue;
@@ -1582,6 +1597,16 @@ static VALUE rb_context_create_isolate_value(VALUE self) {
1582
1597
  return Data_Wrap_Struct(rb_cIsolate, NULL, &deallocate_isolate, isolate_info);
1583
1598
  }
1584
1599
 
1600
+ static void set_ruby_exiting(VALUE value) {
1601
+ (void)value;
1602
+
1603
+ int res = pthread_rwlock_wrlock(&exit_lock);
1604
+ ruby_exiting = true;
1605
+ if (res == 0) {
1606
+ pthread_rwlock_unlock(&exit_lock);
1607
+ }
1608
+ }
1609
+
1585
1610
  extern "C" {
1586
1611
 
1587
1612
  void Init_mini_racer_extension ( void )
@@ -1635,5 +1660,14 @@ extern "C" {
1635
1660
  rb_define_private_method(rb_cIsolate, "init_with_snapshot",(VALUE(*)(...))&rb_isolate_init_with_snapshot, 1);
1636
1661
 
1637
1662
  rb_define_singleton_method(rb_cPlatform, "set_flag_as_str!", (VALUE(*)(...))&rb_platform_set_flag_as_str, 1);
1663
+
1664
+ rb_set_end_proc(set_ruby_exiting, Qnil);
1665
+
1666
+ static pthread_attr_t attr;
1667
+ if (pthread_attr_init(&attr) == 0) {
1668
+ if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) == 0) {
1669
+ thread_attr_p = &attr;
1670
+ }
1671
+ }
1638
1672
  }
1639
1673
  }
@@ -1,3 +1,3 @@
1
1
  module MiniRacer
2
- VERSION = "0.2.10"
2
+ VERSION = "0.2.11"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_racer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.10
4
+ version: 0.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-22 00:00:00.000000000 Z
11
+ date: 2020-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,9 +108,9 @@ licenses:
108
108
  - MIT
109
109
  metadata:
110
110
  bug_tracker_uri: https://github.com/discourse/mini_racer/issues
111
- changelog_uri: https://github.com/discourse/mini_racer/blob/v0.2.10/CHANGELOG
112
- documentation_uri: https://www.rubydoc.info/gems/mini_racer/0.2.10
113
- source_code_uri: https://github.com/discourse/mini_racer/tree/v0.2.10
111
+ changelog_uri: https://github.com/discourse/mini_racer/blob/v0.2.11/CHANGELOG
112
+ documentation_uri: https://www.rubydoc.info/gems/mini_racer/0.2.11
113
+ source_code_uri: https://github.com/discourse/mini_racer/tree/v0.2.11
114
114
  post_install_message:
115
115
  rdoc_options: []
116
116
  require_paths: