Skip to content

Commit

Permalink
Merge pull request #752 from openziti/model-null-ptr-array-fields
Browse files Browse the repository at this point in the history
model_free should set pointer/array fields to NULL
  • Loading branch information
scareything authored Oct 12, 2024
2 parents 2b0f044 + 6bec697 commit 5987040
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions library/model_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,13 +420,15 @@ void model_free(void *obj, const type_meta *meta) {
}
else if (fm->mod == ptr_mod) {
f_ptr = (void *) (*f_addr);
*f_addr = NULL;
if (f_ptr != NULL) {
model_free(f_ptr, field_meta);
free(f_ptr);
}
}
else if (fm->mod == array_mod) {
void **arr = (void **) (*f_addr);
*f_addr = NULL;
if (arr != NULL) {
for (int idx = 0; arr[idx] != NULL; idx++) {
f_ptr = arr + idx;
Expand Down
9 changes: 9 additions & 0 deletions tests/test_ziti_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ TEST_CASE("parse-ctrl-version", "[model]") {
}
},
"buildDate": "2021-04-23 18:09:47",
"capabilities": [ "HA_CONTROLLER", "OIDC_AUTH" ],
"revision": "fe826ed2ec0c",
"runtimeVersion": "go1.16.3",
"version": "v0.19.12"
Expand All @@ -701,6 +702,14 @@ TEST_CASE("parse-ctrl-version", "[model]") {
REQUIRE(v1Path);
REQUIRE_THAT(v1Path->path, Catch::Matchers::Equals("/edge/v1"));

CHECK(*ver.capabilities[0] == ziti_ctrl_cap_HA_CONTROLLER);
CHECK(*ver.capabilities[1] == ziti_ctrl_cap_OIDC_AUTH);
CHECK(ver.capabilities[2] == nullptr);

free_ziti_version(&ver);
CHECK(ver.capabilities == nullptr);
CHECK(ver.api_versions == nullptr);
INFO("should be safe to free object again");
free_ziti_version(&ver);
}

Expand Down

0 comments on commit 5987040

Please sign in to comment.