Fix memory leaks
All checks were successful
Deploy Docs / publish (push) Successful in 21m49s
SwiftLint / SwiftLint (push) Successful in 5s

This commit is contained in:
david-swift 2024-10-31 23:00:50 +01:00
parent 6bf6df0c6f
commit 6229b85f46
59 changed files with 82 additions and 105 deletions

View File

@ -31,7 +31,7 @@ let package = Package(
.package(url: "https://git.aparoksha.dev/aparoksha/meta-sqlite", from: "0.1.0"),
.package(
url: "https://git.aparoksha.dev/aparoksha/levenshtein-transformations",
from: "0.1.0"
branch: "main"
),
.package(url: "https://github.com/CoreOffice/XMLCoder", from: "0.17.1")
],

View File

@ -351,6 +351,7 @@ extension AnyView {
provider?.opaque(),
.init(GTK_STYLE_PROVIDER_PRIORITY_APPLICATION)
)
g_object_unref(provider)
}
}

View File

@ -14,6 +14,7 @@ gtui_filedialog_save_finish (uint64_t dialog, uint64_t result, uint64_t data)
GFile *file = gtk_file_dialog_save_finish (dialog, result, NULL);
const char *path = g_file_get_path (file);
filedialog_on_save_cb (dialog, path, data);
g_object_unref (file);
}
static void

View File

@ -119,7 +119,9 @@ public struct AboutDialog: AdwaitaWidget {
adw_dialog_set_content_height(dialog?.cast(), -1)
} else {
if storage.content[dialogID]?.first != nil {
adw_dialog_close(storage.content[dialogID]?.first?.opaquePointer?.cast())
let dialog = storage.content[dialogID]?.first?.opaquePointer
adw_dialog_close(dialog?.cast())
g_object_unref(dialog?.cast())
}
}
}

View File

@ -135,10 +135,7 @@ public struct AlertDialog: AdwaitaWidget {
let old = storage.fields[Self.responsesID + id] as? [Response] ?? []
old.identifiableTransform(
to: responses,
functions: .init { index, element in
adw_alert_dialog_remove_response(pointer?.cast(), responseID(old[safe: index]?.id))
adw_alert_dialog_add_response(pointer?.cast(), responseID(element.id), element.title)
} delete: { index in
functions: .init { index in
adw_alert_dialog_remove_response(pointer?.cast(), responseID(old[safe: index]?.id))
} insert: { _, element in
adw_alert_dialog_add_response(pointer?.cast(), responseID(element.id), element.title)
@ -160,7 +157,9 @@ public struct AlertDialog: AdwaitaWidget {
}
} else {
if storage.content[Self.dialogID + id]?.first != nil {
adw_dialog_close(storage.content[Self.dialogID + id]?.first?.opaquePointer?.cast())
let dialog = storage.content[Self.dialogID + id]?.first?.opaquePointer
adw_dialog_close(dialog?.cast())
g_object_unref(dialog?.cast())
}
}
}

View File

@ -111,7 +111,9 @@ public struct Dialog: AdwaitaWidget {
}
} else {
if storage.content[dialogID + id]?.first != nil {
adw_dialog_close(storage.content[dialogID + id]?.first?.opaquePointer?.cast())
let dialog = storage.content[dialogID + id]?.first?.opaquePointer
adw_dialog_close(dialog?.cast())
g_object_unref(dialog?.cast())
}
}
}

View File

@ -101,14 +101,17 @@ public struct FileDialog: AdwaitaWidget {
gtk_file_filter_add_suffix(filter, name)
}
gtk_file_dialog_set_default_filter(pointer, filter)
g_object_unref(filter?.cast())
} else {
gtk_file_dialog_set_default_filter(pointer, nil)
}
if let initialFolder {
gtk_file_dialog_set_initial_folder(pointer, g_file_new_for_path(initialFolder.absoluteString))
let file = g_file_new_for_path(initialFolder.absoluteString)
gtk_file_dialog_set_initial_folder(pointer, file)
g_object_unref(file?.cast())
}
let callbacks = AdwaitaFileDialog()
callbacks.onResult = { (storage.fields["result"] as? (URL) -> Void)?($0) }
callbacks.onResult = { (storage.fields["result"] as? (URL) -> Void)?($0); g_object_unref(pointer?.cast()) }
callbacks.onCancel = { (storage.fields["cancel"] as? () -> Void)?() }
callbacks.reset = { storage.fields["callbacks"] = nil }
storage.fields["callbacks"] = callbacks

View File

@ -58,18 +58,10 @@ public struct ForEach<Element>: AdwaitaWidget where Element: Identifiable {
let widget: UnsafeMutablePointer<GtkBox>? = storage.opaquePointer?.cast()
old.identifiableTransform(
to: elements,
functions: .init { index, element in
let child = content(element).storage(data: data, type: type)
gtk_box_remove(widget, contentStorage[safe: index]?.opaquePointer?.cast())
gtk_box_insert_child_after(
widget,
child.opaquePointer?.cast(),
contentStorage[safe: index - 1]?.opaquePointer?.cast()
)
contentStorage.remove(at: index)
contentStorage.insert(child, at: index)
} delete: { index in
gtk_box_remove(widget, contentStorage[safe: index]?.opaquePointer?.cast())
functions: .init { index in
let child = contentStorage[safe: index]?.opaquePointer
gtk_box_remove(widget, child?.cast())
g_object_unref(child?.cast())
contentStorage.remove(at: index)
} insert: { index, element in
let child = content(element).storage(data: data, type: type)

View File

@ -59,10 +59,7 @@ extension ComboRow {
let old = storage.fields[Self.values] as? [Element] ?? []
old.identifiableTransform(
to: values,
functions: .init { index, element in
gtk_string_list_remove(list, .init(index))
gtk_string_list_append(list, element.description)
} delete: { index in
functions: .init { index in
gtk_string_list_remove(list, .init(index))
} insert: { _, element in
gtk_string_list_append(list, element.description)

View File

@ -2,7 +2,7 @@
// ActionRow.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// AspectFrame.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Avatar.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Banner.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Bin.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Box.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Button.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// ButtonContent.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Carousel.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw
@ -124,13 +124,7 @@ public struct Carousel<Element>: AdwaitaWidget where Element: Identifiable {
let old = storage.fields["element"] as? [Element] ?? []
old.identifiableTransform(
to: elements,
functions: .init { index, element in
let child = content(element).storage(data: data, type: type)
adw_carousel_remove(widget, adw_carousel_get_nth_page(widget, UInt(index).cInt))
adw_carousel_insert(widget, child.opaquePointer?.cast(), index.cInt)
contentStorage.remove(at: index)
contentStorage.insert(child, at: index)
} delete: { index in
functions: .init { index in
adw_carousel_remove(widget, adw_carousel_get_nth_page(widget, UInt(index).cInt))
contentStorage.remove(at: index)
} insert: { index, element in

View File

@ -2,7 +2,7 @@
// CenterBox.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// CheckButton.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Clamp.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// ComboRow.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// EntryRow.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// ExpanderRow.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Fixed.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// FlowBox.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw
@ -236,13 +236,7 @@ public struct FlowBox<Element>: AdwaitaWidget where Element: Identifiable {
let old = storage.fields["element"] as? [Element] ?? []
old.identifiableTransform(
to: elements,
functions: .init { index, element in
let child = content(element).storage(data: data, type: type)
gtk_flow_box_remove(widget, gtk_flow_box_get_child_at_index(widget, index.cInt)?.cast())
gtk_flow_box_insert(widget, child.opaquePointer?.cast(), index.cInt)
contentStorage.remove(at: index)
contentStorage.insert(child, at: index)
} delete: { index in
functions: .init { index in
gtk_flow_box_remove(widget, gtk_flow_box_get_child_at_index(widget, index.cInt)?.cast())
contentStorage.remove(at: index)
} insert: { index, element in

View File

@ -2,7 +2,7 @@
// HeaderBar.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Label.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// LevelBar.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// LinkButton.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// ListBox.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw
@ -218,13 +218,7 @@ public struct ListBox<Element>: AdwaitaWidget where Element: Identifiable {
let old = storage.fields["element"] as? [Element] ?? []
old.identifiableTransform(
to: elements,
functions: .init { index, element in
let child = content(element).storage(data: data, type: type)
gtk_list_box_remove(widget, gtk_list_box_get_row_at_index(widget, index.cInt)?.cast())
gtk_list_box_insert(widget, child.opaquePointer?.cast(), index.cInt)
contentStorage.remove(at: index)
contentStorage.insert(child, at: index)
} delete: { index in
functions: .init { index in
gtk_list_box_remove(widget, gtk_list_box_get_row_at_index(widget, index.cInt)?.cast())
contentStorage.remove(at: index)
} insert: { index, element in

View File

@ -2,7 +2,7 @@
// Menu.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// NavigationView.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Overlay.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// OverlaySplitView.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// PasswordEntryRow.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Picture.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Popover.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// PreferencesGroup.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// PreferencesPage.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// PreferencesRow.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// ProgressBar.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// ScrolledWindow.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// SearchBar.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// SearchEntry.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Separator.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// SpinRow.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Spinner.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// SplitButton.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// StatusPage.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// SwitchRow.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// ToastOverlay.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// ToggleButton.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// ToolbarView.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -2,7 +2,7 @@
// WindowTitle.swift
// Adwaita
//
// Created by auto-generation on 26.10.24.
// Created by auto-generation on 31.10.24.
//
import CAdw

View File

@ -32,6 +32,9 @@ extension Picture {
g_bytes_new(ptr.baseAddress, .init(data.count))
}
let texture = gdk_texture_new_from_bytes(bytes, nil)
if let paintable = gtk_picture_get_paintable(pointer) {
g_object_unref(paintable.cast())
}
gtk_picture_set_paintable(pointer, texture)
storage.fields[oldData] = data
}

View File

@ -22,7 +22,11 @@ extension Text {
/// - Parameter ellipsize: Whether it should ellipsize.
/// - Returns: The text widget.
public func ellipsize(_ ellipsize: Bool = true) -> AnyView {
inspect { storage, _ in gtk_label_set_ellipsize(storage.opaquePointer, PANGO_ELLIPSIZE_END) }
inspect { storage, update in
if update {
gtk_label_set_ellipsize(storage.opaquePointer, PANGO_ELLIPSIZE_END)
}
}
}
}

View File

@ -97,10 +97,7 @@ public struct ViewSwitcher<Element>: AdwaitaWidget where Element: ViewSwitcherOp
}
((switcher.previousState as? Self)?.elements ?? []).map { $0.title }.transform(
to: elements.map { $0.title },
functions: .init { index, title in
remove(index)
insert(title)
} delete: { index in
functions: .init { index in
remove(index)
} insert: { _, title in
insert(title)

View File

@ -228,13 +228,7 @@ extension Class {
let old = storage.fields["element"] as? [Element] ?? []
old.identifiableTransform(
to: elements,
functions: .init { index, element in
\(child)
\(dynamicWidget.remove)(\(widget), \(dynamicWidget.getElement))
\(dynamicWidget.insert)(\(widget), \(pointer), index.cInt)
contentStorage.remove(at: index)
contentStorage.insert(child, at: index)
} delete: { index in
functions: .init { index in
\(dynamicWidget.remove)(\(widget), \(dynamicWidget.getElement))
contentStorage.remove(at: index)
} insert: { index, element in