mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-20 02:36:22 +03:00
apprt/gtk-ng: fix config textbuffer memory leak
This commit is contained in:
@ -6,10 +6,7 @@ pub const Surface = @import("gtk-ng/Surface.zig");
|
||||
pub const resourcesDir = internal_os.resourcesDir;
|
||||
|
||||
// The exported API, custom for the apprt.
|
||||
pub const Application = @import("gtk-ng/class/application.zig").Application;
|
||||
pub const Window = @import("gtk-ng/class/window.zig").Window;
|
||||
pub const Config = @import("gtk-ng/class/config.zig").Config;
|
||||
|
||||
pub const class = @import("gtk-ng/class.zig");
|
||||
pub const WeakRef = @import("gtk-ng/weak_ref.zig").WeakRef;
|
||||
|
||||
test {
|
||||
|
26
src/apprt/gtk-ng/class.zig
Normal file
26
src/apprt/gtk-ng/class.zig
Normal file
@ -0,0 +1,26 @@
|
||||
//! This files contains all the GObject classes for the GTK apprt
|
||||
//! along with helpers to work with them.
|
||||
|
||||
const glib = @import("glib");
|
||||
const gobject = @import("gobject");
|
||||
|
||||
pub const Application = @import("class/application.zig").Application;
|
||||
pub const Window = @import("class/window.zig").Window;
|
||||
pub const Config = @import("class/config.zig").Config;
|
||||
|
||||
/// Unrefs the given GObject on the next event loop tick.
|
||||
///
|
||||
/// This works around an issue with zig-object where dynamically
|
||||
/// generated gobjects in property getters can't unref themselves
|
||||
/// normally: https://github.com/ianprime0509/zig-gobject/issues/108
|
||||
pub fn unrefLater(obj: anytype) void {
|
||||
_ = glib.idleAdd((struct {
|
||||
fn callback(data_: ?*anyopaque) callconv(.c) c_int {
|
||||
const remove = @intFromBool(glib.SOURCE_REMOVE);
|
||||
const data = data_ orelse return remove;
|
||||
const object: *gobject.Object = @ptrCast(@alignCast(data));
|
||||
object.unref();
|
||||
return remove;
|
||||
}
|
||||
}).callback, obj.as(gobject.Object));
|
||||
}
|
@ -585,8 +585,8 @@ pub const Application = extern struct {
|
||||
self.as(Parent),
|
||||
);
|
||||
|
||||
const win = Window.new(self);
|
||||
gtk.Window.present(win.as(gtk.Window));
|
||||
// const win = Window.new(self);
|
||||
// gtk.Window.present(win.as(gtk.Window));
|
||||
}
|
||||
|
||||
fn dispose(self: *Self) callconv(.C) void {
|
||||
|
@ -1,12 +1,15 @@
|
||||
const std = @import("std");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const adw = @import("adw");
|
||||
const glib = @import("glib");
|
||||
const gobject = @import("gobject");
|
||||
const gtk = @import("gtk");
|
||||
|
||||
const configpkg = @import("../../../config.zig");
|
||||
const CoreConfig = configpkg.Config;
|
||||
|
||||
const unrefLater = @import("../class.zig").unrefLater;
|
||||
|
||||
const log = std.log.scoped(.gtk_ghostty_config);
|
||||
|
||||
/// Wraps a `Ghostty.Config` object in a GObject so it can be reference
|
||||
@ -125,6 +128,7 @@ pub const Config = extern struct {
|
||||
text_buf.insertAtCursor("\n", 1);
|
||||
}
|
||||
|
||||
unrefLater(text_buf); // See unrefLater docs for why this is needed
|
||||
return text_buf;
|
||||
}
|
||||
|
||||
|
@ -140,6 +140,20 @@
|
||||
...
|
||||
}
|
||||
|
||||
{
|
||||
pango font map to cairgo
|
||||
Memcheck:Leak
|
||||
match-leak-kinds: possible
|
||||
fun:malloc
|
||||
...
|
||||
fun:FcConfigValues
|
||||
fun:FcConfigSubstituteWithPat
|
||||
fun:FcConfigSubstitute
|
||||
fun:pango_cairo_fc_font_map_fontset_key_substitute
|
||||
fun:pango_fc_font_map_load_fontset
|
||||
...
|
||||
}
|
||||
|
||||
{
|
||||
Adwaita Stylesheet Load
|
||||
Memcheck:Leak
|
||||
|
Reference in New Issue
Block a user