Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue with dynamically created array of pointers with cffi #586

Merged
merged 2 commits into from Aug 17, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions kapitan/inputs/helm/__init__.py
Expand Up @@ -130,10 +130,18 @@ def render_chart(self, chart_dir, output_path, **kwargs):
char_dir_buf = ffi.new("char[]", chart_dir.encode("ascii"))
output_path_buf = ffi.new("char[]", output_path.encode("ascii"))

# as noted in cffi documentation, once the reference to the pointer is out of scope, the data is freed.
# to prevent that from happening with these dynamic arrays, we create a 'keep_pointers_alive' dict
# https://cffi.readthedocs.io/en/latest/using.html#working-with-pointers-structures-and-arrays
helm_values_files = []
keep_pointers_alive = dict()
if kwargs.get("helm_values_files", []):
for file_name in kwargs["helm_values_files"]:
helm_values_files.append(ffi.new("char[]", file_name.encode("ascii")))
for i in range(len(kwargs["helm_values_files"])):
file_name = kwargs["helm_values_files"][i]

ptr_to_encoded_file_name = ffi.new("char[]", file_name.encode("ascii"))
keep_pointers_alive[file_name + str(i)] = ptr_to_encoded_file_name
helm_values_files.append(ptr_to_encoded_file_name)

helm_values_files_len = ffi.cast("int", len(helm_values_files))
helm_values_files = ffi.new("char *[]", helm_values_files)
Expand Down