Skip to content

Potential memory leak in Objects/bytesobject.c #101056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
RuiliF opened this issue Jan 15, 2023 · 4 comments
Closed

Potential memory leak in Objects/bytesobject.c #101056

RuiliF opened this issue Jan 15, 2023 · 4 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@RuiliF
Copy link

RuiliF commented Jan 15, 2023

Bug report

p = PyOS_double_to_string(x, type, prec, dtoa_flags, NULL);
if (p == NULL)
return NULL;
len = strlen(p);
if (writer != NULL) {
str = _PyBytesWriter_Prepare(writer, str, len);
if (str == NULL)
return NULL;
memcpy(str, p, len);
PyMem_Free(p);
str += len;
return str;
}

At line 438, object p won't be freed if _PyBytesWriter_Prepare fails (returns NULL) and thus become a memory leak.

Linked PRs

@RuiliF RuiliF added the type-bug An unexpected behavior, bug, or error label Jan 15, 2023
sobolevn added a commit to sobolevn/cpython that referenced this issue Jan 15, 2023
@sobolevn
Copy link
Member

Good catch! @RuiliF thanks a lot!

How do you detect it? Do you use some kind of tooling? Or just by hand? :)

@RuiliF
Copy link
Author

RuiliF commented Jan 15, 2023

Good catch! @RuiliF thanks a lot!

How do you detect it? Do you use some kind of tooling? Or just by hand? :)

Thank you for the quick response! I found it just by hand. :)

@sobolevn
Copy link
Member

If you have others to report - you are more than welcome! 👍

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jan 16, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jan 16, 2023
miss-islington added a commit that referenced this issue Jan 16, 2023
…101057)

(cherry picked from commit b1a74a1)

Co-authored-by: Nikita Sobolev <[email protected]>
miss-islington added a commit that referenced this issue Jan 16, 2023
…101057)

(cherry picked from commit b1a74a1)

Co-authored-by: Nikita Sobolev <[email protected]>
@sobolevn
Copy link
Member

Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants