diff --git a/src/libstore-c/nix_api_store.cc b/src/libstore-c/nix_api_store.cc index b95e5b749..0869fc91d 100644 --- a/src/libstore-c/nix_api_store.cc +++ b/src/libstore-c/nix_api_store.cc @@ -215,7 +215,11 @@ void nix_derivation_free(nix_derivation * drv) StorePath * nix_store_path_clone(const StorePath * p) { - return new StorePath{p->path}; + try { + return new StorePath{p->path}; + } catch (...) { + return nullptr; + } } nix_derivation * nix_derivation_from_json(nix_c_context * context, Store * store, const char * json) diff --git a/src/libutil-c/nix_api_util.cc b/src/libutil-c/nix_api_util.cc index a2f7710bc..f28a9168e 100644 --- a/src/libutil-c/nix_api_util.cc +++ b/src/libutil-c/nix_api_util.cc @@ -13,7 +13,11 @@ extern "C" { nix_c_context * nix_c_context_create() { - return new nix_c_context(); + try { + return new nix_c_context(); + } catch (...) { + return nullptr; + } } void nix_c_context_free(nix_c_context * context)