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

Feature: Implement ucl_iterate_object_end #313

Open
kevemueller opened this issue Dec 4, 2024 · 0 comments
Open

Feature: Implement ucl_iterate_object_end #313

kevemueller opened this issue Dec 4, 2024 · 0 comments

Comments

@kevemueller
Copy link

In a codebase heavily relying on UCL (https://github.com/freebsd/pkg) there is a recurring programming error causing a memory leak involving ucl_iterate_object.

When the iteration is abandoned in-flight, the iterator itself is never freed.
E.g. (abbreviated)

	ucl_object_iter_t it = NULL;
	while ((cur = ucl_iterate_object(obj, &it, true))) {
		if (error) {
			return (EPKG_FATAL); // it is leaked here
		}
	}

Not in every context is it possible to introduce UCL_FREE (sizeof (*it), it);, also it is not evident that that this is the only thing that needs to be done with the iterator.

I suggest introducing ucl_iterate_object_end(ucl_object_iter_t *iter) that can be called before abandoning iteration which does whatever is needed to be done to close the iterator and free all its resources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant