Skip to content

Commit 79b019e

Browse files
committed
c-api: fix a few memory leaks
1 parent 47e2381 commit 79b019e

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

src/libexpr-c/nix_api_expr.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ EvalState * nix_state_create(nix_c_context * context, const char ** lookupPath_c
199199
!= NIX_OK)
200200
return nullptr;
201201

202-
return nix_eval_state_build(context, builder);
202+
auto *state = nix_eval_state_build(context, builder);
203+
nix_eval_state_builder_free(builder);
204+
return state;
203205
}
204206

205207
void nix_state_free(EvalState * state)

src/libexpr-tests/nix_api_external.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ TEST_F(nix_api_expr_test, nix_expr_eval_external)
6363
std::string string_value;
6464
nix_get_string(nullptr, valueResult, OBSERVE_STRING(string_value));
6565
ASSERT_STREQ("nix-external<MyExternalValueDesc( 42 )>", string_value.c_str());
66+
67+
nix_state_free(stateResult);
68+
nix_state_free(stateFn);
6669
}
6770

6871
}

src/libflake-tests/nix_api_flake.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ TEST_F(nix_api_store_test, nix_api_init_global_getFlake_exists)
4343
ASSERT_NE(nullptr, value);
4444

4545
nix_err err = nix_expr_eval_from_string(ctx, state, "builtins.getFlake", ".", value);
46+
47+
nix_state_free(state);
48+
4649
assert_ctx_ok();
4750
ASSERT_EQ(NIX_OK, err);
4851
ASSERT_EQ(NIX_TYPE_FUNCTION, nix_get_type(ctx, value));

0 commit comments

Comments
 (0)