FriendlyCaps: Fix memory leak
All checks were successful
PostmarketOS Build / Prepare (push) Successful in 29s
PostmarketOS Build / Build for aarch64 (push) Successful in 1m1s
PostmarketOS Build / Build for x86_64 (push) Successful in 24s

Signed-off-by: Vasiliy Doylov <nekocwd@mainlining.org>
This commit is contained in:
Vasiliy Doylov 2025-06-21 22:22:52 +03:00
parent 126504d740
commit 6c1fb2e13a
Signed by: NekoCWD
GPG key ID: B7BE22D44474A582
2 changed files with 12 additions and 16 deletions

View file

@ -31,8 +31,10 @@ public class EyeNeko.Gstreamer : Object {
can_start_stream = false; can_start_stream = false;
available_caps.remove_all (); available_caps.remove_all ();
for (uint i = 0; i < caps.get_size (); i++) { for (uint i = 0; i < caps.get_size (); i++) {
var cap = new FriendlyCaps.with_struct (caps.get_structure (i)); var cap = new Gst.Caps.empty ();
available_caps.append (cap); cap.append_structure (caps.get_structure (i).copy ());
var fcap = new FriendlyCaps.with_caps (cap);
available_caps.append (fcap);
} }
can_start_stream = true; can_start_stream = true;
caps_selecton_model.selected = 0; caps_selecton_model.selected = 0;

View file

@ -1,6 +1,6 @@
namespace EyeNeko { namespace EyeNeko {
public class FriendlyCaps : Object { public class FriendlyCaps : Object {
public unowned Gst.Structure struct { get; construct set; } public Gst.Caps caps { get; construct set; }
public enum Format { public enum Format {
RAW, RAW,
JPEG, JPEG,
@ -35,12 +35,12 @@ namespace EyeNeko {
public string pixelformat { get; default = ""; } public string pixelformat { get; default = ""; }
construct { construct {
struct.get_int ("width", out _width); caps.get_structure (0).get_int ("width", out _width);
struct.get_int ("height", out _height); caps.get_structure (0).get_int ("height", out _height);
_format_name = struct.get_name (); _format_name = caps.get_structure (0).get_name ();
_format = Format.from_gst_name (format_name); _format = Format.from_gst_name (format_name);
_pixelformat = struct.get_string ("format"); int num, denom; _pixelformat = caps.get_structure (0).get_string ("format"); int num, denom;
struct.get_fraction ("framerate", out num, out denom); caps.get_structure (0).get_fraction ("framerate", out num, out denom);
if (denom == 0) if (denom == 0)
denom = 1; denom = 1;
_fps = num / denom; _fps = num / denom;
@ -51,11 +51,7 @@ namespace EyeNeko {
warning ("Unsupported caps structute count (%u)", caps.get_size ()); warning ("Unsupported caps structute count (%u)", caps.get_size ());
return; return;
} }
Object (struct : caps.get_structure (0).copy ()); Object (caps: caps);
}
public FriendlyCaps.with_struct (Gst.Structure struct) {
Object (struct : struct);
} }
public string to_string () { public string to_string () {
@ -80,9 +76,7 @@ namespace EyeNeko {
} }
public Gst.Caps to_caps () { public Gst.Caps to_caps () {
var res = new Gst.Caps.empty (); return caps.copy ();
res.append_structure (struct.copy ());
return res;
} }
} }
} }