Fix incorrectly cleaning up data archive memory in app context
This commit is contained in:
parent
449b56947e
commit
3d3d0e488a
27
src/oar.zig
27
src/oar.zig
|
@ -3,7 +3,7 @@ const sys = @import("./sys.zig");
|
||||||
const table = @import("./table.zig");
|
const table = @import("./table.zig");
|
||||||
|
|
||||||
///
|
///
|
||||||
///
|
/// Thin file-wrapper and in-memory layout cache of an OAR archive file.
|
||||||
///
|
///
|
||||||
pub const Archive = struct {
|
pub const Archive = struct {
|
||||||
file_access: sys.FileAccess,
|
file_access: sys.FileAccess,
|
||||||
|
@ -17,15 +17,28 @@ pub const Archive = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
///
|
///
|
||||||
///
|
/// See [std.mem.Allocator.Error].
|
||||||
///
|
///
|
||||||
pub const InitError = std.mem.Allocator.Error;
|
pub const InitError = std.mem.Allocator.Error;
|
||||||
|
|
||||||
///
|
///
|
||||||
|
/// In-memory archive layout cache.
|
||||||
///
|
///
|
||||||
|
/// As the archive is queried via [find], the cache is lazily assembled with the absolute
|
||||||
|
/// offsets of each queried file.
|
||||||
///
|
///
|
||||||
const IndexCache = table.Hashed([]const u8, u64, table.string_context);
|
const IndexCache = table.Hashed([]const u8, u64, table.string_context);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Deinitializes the index cache of `archive`, freeing all associated memory.
|
||||||
|
///
|
||||||
|
/// **Note** that this does nothing to the [FileAccess] value that was provided as part of
|
||||||
|
/// [init].
|
||||||
|
///
|
||||||
|
pub fn deint(archive: *Archive) void {
|
||||||
|
archive.index_cache.deinit();
|
||||||
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Finds an entry matching `entry_path` in `archive`.
|
/// Finds an entry matching `entry_path` in `archive`.
|
||||||
///
|
///
|
||||||
|
@ -90,11 +103,17 @@ pub const Archive = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
/// Attempts to initialize a new [Archive] with `cache_allocator` as the allocator for managing
|
||||||
|
/// the in-memory archive layout caches and `archive_file_access` as the currently open archive
|
||||||
|
/// file.
|
||||||
///
|
///
|
||||||
|
/// **Note** that `archive_file_access` does nothing to manage the lifetime of the open file.
|
||||||
///
|
///
|
||||||
pub fn init(allocator: std.mem.Allocator, archive_file_access: sys.FileAccess) InitError!Archive {
|
pub fn init(cache_allocator: std.mem.Allocator,
|
||||||
|
archive_file_access: sys.FileAccess) InitError!Archive {
|
||||||
|
|
||||||
return Archive{
|
return Archive{
|
||||||
.index_cache = try IndexCache.init(allocator),
|
.index_cache = try IndexCache.init(cache_allocator),
|
||||||
.file_access = archive_file_access,
|
.file_access = archive_file_access,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,9 +102,10 @@ pub const AppContext = opaque {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
implementation.data_file_system.archive.instance.deint();
|
||||||
|
ext.SDL_free(implementation.user_path_prefix);
|
||||||
ext.SDL_DestroyMutex(implementation.message_mutex);
|
ext.SDL_DestroyMutex(implementation.message_mutex);
|
||||||
ext.SDL_DestroySemaphore(implementation.message_semaphore);
|
ext.SDL_DestroySemaphore(implementation.message_semaphore);
|
||||||
ext.SDL_free(implementation.user_path_prefix);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in New Issue