Skip to content

Commit 68215ea

Browse files
committed
[Python] Ensure that BNFreeParseError is used to free the error returned by BNParseExpression
1 parent 9b7c23d commit 68215ea

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

python/binaryview.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10872,7 +10872,7 @@ def parse_expression(self, expression: str, here: int = 0) -> int:
1087210872
if not core.BNParseExpression(self.handle, expression, offset, here, errors):
1087310873
assert errors.value is not None, "core.BNParseExpression returned errors set to None"
1087410874
error_str = errors.value.decode("utf-8")
10875-
core.free_string(errors)
10875+
core.BNFreeParseError(ctypes.cast(errors, ctypes.POINTER(ctypes.c_byte)))
1087610876
raise ValueError(error_str)
1087710877
return offset.value
1087810878

python/generator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ int main(int argc, char* argv[])
504504

505505
// From python -> C python3 requires str -> str.encode('charmap')
506506
bool swizzleArgs = true;
507-
if (name == "BNFreeString")
507+
if (name == "BNFreeString" || name == "BNFreeParseError")
508508
swizzleArgs = false;
509509

510510
bool callbackConvention = false;
@@ -531,9 +531,9 @@ int main(int argc, char* argv[])
531531
for (auto& j : i.second->GetParameters())
532532
{
533533
fprintf(out, "\t\t");
534-
if (name == "BNFreeString")
534+
if (name == "BNFreeString" || name == "BNFreeParseError")
535535
{
536-
// BNFreeString expects a pointer to a string allocated by the core, so do not use
536+
// These expect a pointer to a string allocated by the core, so do not use
537537
// a c_char_p here, as that would be allocated by the Python runtime. This can
538538
// be enforced by outputting like a return value.
539539
OutputType(out, j.type.GetValue(), true);

0 commit comments

Comments
 (0)