properly free Image contents
This commit is contained in:
parent
77cceab288
commit
c2834f8254
2 changed files with 8 additions and 4 deletions
|
@ -179,17 +179,20 @@ pub const Image = struct {
|
|||
}
|
||||
|
||||
pub fn close(self: *Image) void {
|
||||
self.allocator.free(self.path);
|
||||
self.allocator.free(self.curpath);
|
||||
|
||||
var st: i32 = c.sf_close(self.sndfile);
|
||||
|
||||
if (st != 0) {
|
||||
std.debug.warn("Failed to close {} ({})\n", .{
|
||||
self.path,
|
||||
c.sf_error_number(st),
|
||||
});
|
||||
}
|
||||
|
||||
self.allocator.free(self.path);
|
||||
self.allocator.free(self.curpath);
|
||||
|
||||
var allocator = self.allocator;
|
||||
self.* = undefined;
|
||||
allocator.destroy(self);
|
||||
}
|
||||
|
||||
pub fn read(self: *Image, file_chans: c_int, buf: []f32) bool {
|
||||
|
|
|
@ -108,6 +108,7 @@ pub const Runner = struct {
|
|||
// we don't copy load_path into a temporary file because we're already
|
||||
// loading it under the SFM_READ mode, which won't cause any destructive
|
||||
// operations on the file.
|
||||
if (self.image) |image| image.close();
|
||||
self.image = try Image.open(self.allocator, load_path);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue