fix: make sure project state is freed with the correct allocator

This commit is contained in:
CJ van den Berg 2025-11-26 15:55:47 +01:00
parent 20129ea773
commit c8840f0756
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 7 additions and 4 deletions

View file

@ -75,17 +75,18 @@ pub fn open(rel_project_directory: []const u8) (ProjectManagerError || FileSyste
const project_state_allocator = std.heap.c_allocator;
var project_state_mutex: std.Thread.Mutex = .{};
var project_state: ProjectStateMap = .empty;
const ProjectStateMap = std.StringHashMapUnmanaged([]const u8);
const ProjectStateMap = std.StringHashMapUnmanaged(std.array_list.Managed(u8));
fn get_project_state(project_directory: []const u8) ?[]const u8 {
project_state_mutex.lock();
defer project_state_mutex.unlock();
return project_state.get(project_directory);
return if (project_state.get(project_directory)) |state| state.items else null;
}
pub fn store_state(project_directory: []const u8, state: []const u8) error{OutOfMemory}!void {
pub fn store_state(project_directory: []const u8, state: std.array_list.Managed(u8)) error{OutOfMemory}!void {
project_state_mutex.lock();
defer project_state_mutex.unlock();
if (project_state.fetchRemove(project_directory)) |old_state| old_state.value.deinit();
try project_state.put(project_state_allocator, try project_state_allocator.dupe(u8, project_directory), state);
}