Skip to content

Commit 689d045

Browse files
Duo YiDuoYi
authored andcommitted
Fix a memory leak issue with ynl
std::optional<> cannot be initialized directly by &{var}->{c_name}. adding emplace() fixed the issue.
1 parent c7c4975 commit 689d045

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

ynl-gen-cpp.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
SpecOperation,
2020
)
2121

22+
2223
def c_upper(name):
2324
return name.upper().replace("-", "_")
2425

@@ -172,7 +173,7 @@ def attr_typol(self, cw):
172173
cw.p(f'arr[{self.enum_name}].name = "{self.name}";')
173174

174175
for key, val in self._attr_typol().items():
175-
cw.p(f'arr[{self.enum_name}].{key} = {val};')
176+
cw.p(f"arr[{self.enum_name}].{key} = {val};")
176177

177178
def _attr_put_line(self, ri, var, line):
178179
if self.presence_type() == "flag":
@@ -549,7 +550,7 @@ def _complex_member_type(self, ri):
549550
return self.nested_struct_type
550551

551552
def _attr_typol(self):
552-
return {"type": "YNL_PT_NEST", "nest": f"&{self.nested_render_name}_nest" }
553+
return {"type": "YNL_PT_NEST", "nest": f"&{self.nested_render_name}_nest"}
553554

554555
def _attr_policy(self, policy):
555556
return "NLA_POLICY_NESTED(" + self.nested_render_name + "_nl_policy)"
@@ -571,7 +572,7 @@ def _attr_get(self, ri, var):
571572
]
572573
init_lines = [
573574
f"parg.rsp_policy = &{self.nested_render_name}_nest;",
574-
f"parg.data = &{var}->{self.c_name};",
575+
f"parg.data = &{var}->{self.c_name}.emplace();",
575576
]
576577
return get_lines, init_lines, None
577578

@@ -681,7 +682,7 @@ def _attr_get(self, ri, var):
681682
local_vars = []
682683
init_lines = [
683684
f"parg.rsp_policy = &{self.nested_render_name}_nest;",
684-
f"parg.data = &{var}->{self.c_name};",
685+
f"parg.data = &{var}->{self.c_name}.emplace();",
685686
]
686687
if "type-value" in self.attr:
687688
tv_names = [c_lower(x) for x in self.attr["type-value"]]

0 commit comments

Comments
 (0)