Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

socketmodule.c: Reference and buffer leaks via audit hook failures #146245

Copy link
Copy link
@aisk

Description

@aisk
Issue body actions

Bug report

Bug description:

Summary

Two leak bugs in socketmodule.c triggered when PySys_Audit raises:

  1. getaddrinfo (line 6983): idna and/or pstr refs leaked when audit hook raises. ~657 objects leaked per 1000 calls.
  2. sock_sendto (line 4810): pbuf Py_buffer not released when audit hook raises.

Reproducer (getaddrinfo leak)

import socket, sys

sys.addaudithook(lambda *a: (_ for _ in ()).throw(RuntimeError("audit")))
before = sys.gettotalrefcount()
for i in range(1000):
    try:
        socket.getaddrinfo("localhost", 80)
    except RuntimeError:
        pass
after = sys.gettotalrefcount()
print(f"Leaked {after - before} objects in 1000 calls")

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.