Skip to content

Potential memory leak in Objects/bytesobject.c #101056

Description

@RuiliF

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

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Jan 15, 2023
  2. added a commit that references this issue on Jan 15, 2023
  3. sobolevn commented on Jan 15, 2023

    @sobolevn
    Member

    Good catch! @RuiliF thanks a lot!

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

  4. RuiliF commented on Jan 15, 2023

    @RuiliF
    Author

    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. :)

  5. sobolevn commented on Jan 15, 2023

    @sobolevn
    Member

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

  6. added a commit that references this issue on Jan 16, 2023
  7. added 4 commits that reference this issue on Jan 16, 2023
  8. sobolevn commented on Jan 17, 2023

    @sobolevn
    Member

    Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions