Skip to content

Commit

Permalink
fix: mupdf mem leak
Browse files Browse the repository at this point in the history
  • Loading branch information
freref committed Feb 27, 2025
1 parent ea12b35 commit 95e06a4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/PdfHandler.zig
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,16 @@ pub fn deinit(self: *Self) void {
}

pub fn reloadDocument(self: *Self) !void {
if (self.temp_doc) |doc| {
c.fz_drop_document(self.ctx, doc);
self.temp_doc = null;
}

self.temp_doc = c.fz_open_document(self.ctx, self.path.ptr) orelse {
std.debug.print("Failed to reload document\n", .{});
return PdfError.FailedToOpenDocument;
};
// TODO check this more efficient

self.total_pages = @as(u16, @intCast(c.fz_count_pages(self.ctx, self.temp_doc.?)));
if (self.current_page_number >= self.total_pages) {
self.current_page_number = self.total_pages - 1;
Expand Down

0 comments on commit 95e06a4

Please sign in to comment.