~bitfehler/apk-index-update

04af8b4868c4a242f535eeb160c2190fa95c6072 — Conrad Hoffmann 6 months ago 1927d4f
Fix all memory issues
1 files changed, 9 insertions(+), 4 deletions(-)

M main.ha
M main.ha => main.ha +9 -4
@@ 58,6 58,7 @@ fn write_index(index: []package, f: io::handle) void = {
fn free_all(packages: []package) void = {
	for (let i = 0z; i < len(packages); i += 1) {
		strings::freeall(packages[i].props);
		free(packages[i].name);
	};
	free(packages);
};


@@ 95,14 96,18 @@ export fn main() void = {
	let new_packages = read_index(os::stdin_file)!;
	defer free_all(new_packages);

	let all_packages: []package = [];
	defer free(all_packages);
	append(all_packages, base_packages...);

	for (let i = 0z; i < len(new_packages); i += 1) {
		match (index(base_packages, new_packages[i].name)) {
		match (index(all_packages, new_packages[i].name)) {
		case let idx: size =>
			base_packages[idx] = new_packages[i];
			all_packages[idx] = new_packages[i];
		case =>
			append(base_packages, new_packages[i]);
			append(all_packages, new_packages[i]);
		};
	};

	write_index(base_packages, os::stdout);
	write_index(all_packages, os::stdout);
};