You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2022/04/28 18:32:14 UTC

[arrow] branch master updated: ARROW-16390: [C++] Dataset initialization could segfault if called simultaneously

This is an automated email from the ASF dual-hosted git repository.

westonpace pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new 069b747816 ARROW-16390: [C++] Dataset initialization could segfault if called simultaneously
069b747816 is described below

commit 069b74781643e10338bebf4b34857e49573887c8
Author: Weston Pace <we...@gmail.com>
AuthorDate: Thu Apr 28 08:31:53 2022 -1000

    ARROW-16390: [C++] Dataset initialization could segfault if called simultaneously
    
    Closes #13019 from westonpace/bugfix/ARROW-16390--possible-to-double-init-datasets
    
    Authored-by: Weston Pace <we...@gmail.com>
    Signed-off-by: Weston Pace <we...@gmail.com>
---
 cpp/src/arrow/dataset/plan.cc | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/cpp/src/arrow/dataset/plan.cc b/cpp/src/arrow/dataset/plan.cc
index 9b222ff578..01169413f7 100644
--- a/cpp/src/arrow/dataset/plan.cc
+++ b/cpp/src/arrow/dataset/plan.cc
@@ -21,17 +21,21 @@
 #include "arrow/dataset/file_base.h"
 #include "arrow/dataset/scanner.h"
 
+#include <mutex>
+
 namespace arrow {
 namespace dataset {
 namespace internal {
 
 void Initialize() {
-  static auto registry = compute::default_exec_factory_registry();
-  if (registry) {
-    InitializeScanner(registry);
-    InitializeDatasetWriter(registry);
-    registry = nullptr;
-  }
+  static std::once_flag flag;
+  std::call_once(flag, [] {
+    auto registry = compute::default_exec_factory_registry();
+    if (registry) {
+      InitializeScanner(registry);
+      InitializeDatasetWriter(registry);
+    }
+  });
 }
 
 }  // namespace internal