Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Fix bad delete.
Browse files Browse the repository at this point in the history
Delete the pointed-to handle on cleanup, not the location of the handle itself. Also don't delete it if we didn't set it in the first place.
  • Loading branch information
Taliesin Beynon committed Nov 24, 2018
1 parent 1e4afd5 commit 0631d17
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/c_api/c_api_executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,11 @@ int MXExecutorReshape(int partial_shaping,
NDArrayHandle** aux_states,
ExecutorHandle shared_exec,
ExecutorHandle *out) {
Executor* new_exec = nullptr;

MXAPIThreadLocalEntry *ret = MXAPIThreadLocalStore::Get();
API_BEGIN();
*out = nullptr; // ensure we can know whether to free executor on early abort
// create shape map for in_args and aux_states
std::unordered_map<std::string, TShape> kwargs(num_provided_arg_shapes);
for (mx_uint i = 0; i < num_provided_arg_shapes; ++i) {
Expand All @@ -581,8 +584,9 @@ int MXExecutorReshape(int partial_shaping,
std::vector<NDArray> aux_state_vec;

Executor* exec = static_cast<Executor*>(shared_exec);
*out = exec->Reshape(partial_shaping, allow_up_sizing, ctx, ctx_map, kwargs,
new_exec = exec->Reshape(partial_shaping, allow_up_sizing, ctx, ctx_map, kwargs,
&in_arg_vec, &arg_grad_vec, &aux_state_vec);
*out = new_exec;

ret->ret_handles.clear();
ret->ret_handles.reserve(in_arg_vec.size()+arg_grad_vec.size()+aux_state_vec.size());
Expand Down Expand Up @@ -623,7 +627,7 @@ int MXExecutorReshape(int partial_shaping,
*aux_states = &(ret->ret_handles[nd_idx]);
nd_idx = ret->ret_handles.size();
}
API_END_HANDLE_ERROR(delete out);
API_END_HANDLE_ERROR(if (new_exec != nullptr) { delete new_exec; });
}

int MXExecutorGetOptimizedSymbol(ExecutorHandle handle,
Expand Down

0 comments on commit 0631d17

Please sign in to comment.