mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
fix: resolve memory leak in Option.getText() by using page arena
This commit is contained in:
@@ -231,7 +231,7 @@ fn extractSelectOptions(node: *Node, page: *Page, arena: std.mem.Allocator) ![]O
|
||||
if (child.is(Element)) |el| {
|
||||
if (el.getTag() == .option) {
|
||||
if (el.is(Element.Html.Option)) |opt| {
|
||||
const text = opt.getText();
|
||||
const text = opt.getText(page);
|
||||
const value = opt.getValue(page);
|
||||
const selected = opt.getSelected();
|
||||
try options.append(arena, .{ .text = text, .value = value, .selected = selected });
|
||||
@@ -240,7 +240,7 @@ fn extractSelectOptions(node: *Node, page: *Page, arena: std.mem.Allocator) ![]O
|
||||
var group_it = child.childrenIterator();
|
||||
while (group_it.next()) |group_child| {
|
||||
if (group_child.is(Element.Html.Option)) |opt| {
|
||||
const text = opt.getText();
|
||||
const text = opt.getText(page);
|
||||
const value = opt.getValue(page);
|
||||
const selected = opt.getSelected();
|
||||
try options.append(arena, .{ .text = text, .value = value, .selected = selected });
|
||||
|
||||
@@ -61,10 +61,9 @@ pub fn setValue(self: *Option, value: []const u8, page: *Page) !void {
|
||||
self._value = owned;
|
||||
}
|
||||
|
||||
pub fn getText(self: *const Option) []const u8 {
|
||||
pub fn getText(self: *const Option, page: *Page) []const u8 {
|
||||
const node: *Node = @constCast(self.asConstElement().asConstNode());
|
||||
const allocator = std.heap.page_allocator; // TODO: use proper allocator
|
||||
return node.getTextContentAlloc(allocator) catch "";
|
||||
return node.getTextContentAlloc(page.call_arena) catch "";
|
||||
}
|
||||
|
||||
pub fn setText(self: *Option, value: []const u8, page: *Page) !void {
|
||||
|
||||
Reference in New Issue
Block a user