From: Jacob Lifshay Date: Tue, 22 Aug 2017 23:40:53 +0000 (-0700) Subject: fix reference after free bug in orc compile stack X-Git-Tag: gsoc-2017~33 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=11a29c9536f8593b6f4bf96b65a1b82a17d787d9;p=kazan.git fix reference after free bug in orc compile stack --- diff --git a/src/llvm_wrapper/orc_compile_stack.cpp b/src/llvm_wrapper/orc_compile_stack.cpp index c0f6720..86f0ef3 100644 --- a/src/llvm_wrapper/orc_compile_stack.cpp +++ b/src/llvm_wrapper/orc_compile_stack.cpp @@ -75,6 +75,34 @@ private: My_object_linking_layer &operator=(My_object_linking_layer &&) = delete; private: + struct Object_set_wrapper + { + typedef std::unique_ptr> + value_type; + const value_type *objects; + std::size_t object_count; + explicit Object_set_wrapper(const std::vector &objects) noexcept + : objects(objects.data()), + object_count(objects.size()) + { + } + auto begin() const noexcept + { + return objects; + } + auto end() const noexcept + { + return objects + object_count; + } + std::size_t size() const noexcept + { + return object_count; + } + auto &operator[](std::size_t index) const noexcept + { + return objects[index]; + } + }; class On_loaded_functor { friend class My_object_linking_layer; @@ -89,8 +117,7 @@ private: public: void operator()( llvm::orc::ObjectLinkingLayerBase::ObjSetHandleT, - const std:: - vector>> + const Object_set_wrapper &object_set, const std::vector> &load_result) @@ -165,8 +192,9 @@ private: { auto retval = create_module_handle(); auto &handle = handle_map[retval]; + auto object_set_iter = object_sets.insert(object_sets.end(), std::move(object_set)); handle = object_linking_layer.addObjectSet( - std::move(object_set), std::move(memory_manager), std::move(symbol_resolver)); + Object_set_wrapper(*object_set_iter), std::move(memory_manager), std::move(symbol_resolver)); return retval; } @@ -175,6 +203,7 @@ private: std::vector> jit_event_listener_list; llvm::orc::ObjectLinkingLayer object_linking_layer; std::unordered_map handle_map; + std::list>>> object_sets; std::unordered_multiset loaded_object_set; }; typedef std::function(std::unique_ptr)>