]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-139748: Fix socket.if_nametoindex() Argument Clinic (#139815)
authorVictor Stinner <vstinner@python.org>
Wed, 8 Oct 2025 23:24:30 +0000 (01:24 +0200)
committerGitHub <noreply@github.com>
Wed, 8 Oct 2025 23:24:30 +0000 (23:24 +0000)
gh-139748: Fix socket.if_nametoindex() Argument Clinic

Fix a reference leak.

Modules/clinic/socketmodule.c.h
Modules/socketmodule.c

index 3f4056efff2fec542f0ce48367d9708d4b6ae8ff..4db27a441f85a6ab4f67d0b9c6aa9e2f09d38476 100644 (file)
@@ -239,7 +239,7 @@ static PyObject *
 _socket_socket_if_nametoindex(PySocketSockObject *self, PyObject *arg)
 {
     PyObject *return_value = NULL;
-    PyObject *oname;
+    PyObject *oname = NULL;
 
     if (!PyUnicode_FSConverter(arg, &oname)) {
         goto exit;
@@ -247,6 +247,9 @@ _socket_socket_if_nametoindex(PySocketSockObject *self, PyObject *arg)
     return_value = _socket_socket_if_nametoindex_impl(self, oname);
 
 exit:
+    /* Cleanup for oname */
+    Py_XDECREF(oname);
+
     return return_value;
 }
 
@@ -259,4 +262,4 @@ exit:
 #ifndef _SOCKET_SOCKET_IF_NAMETOINDEX_METHODDEF
     #define _SOCKET_SOCKET_IF_NAMETOINDEX_METHODDEF
 #endif /* !defined(_SOCKET_SOCKET_IF_NAMETOINDEX_METHODDEF) */
-/*[clinic end generated code: output=eb37b5d88a1e4661 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=2a58294cf2c87e33 input=a9049054013a1b77]*/
index a6910df6fba64e556c4594fefafd9aca539cc876..af7f81701b01aa8f3c7f775afa8abd3b6f2ff0c3 100644 (file)
@@ -7098,7 +7098,7 @@ Returns a list of network interface information (index, name) tuples.");
 
 /*[clinic input]
 _socket.socket.if_nametoindex
-    oname: object(converter="PyUnicode_FSConverter")
+    oname: unicode_fs_encoded
     /
 
 Returns the interface index corresponding to the interface name if_name.
@@ -7106,7 +7106,7 @@ Returns the interface index corresponding to the interface name if_name.
 
 static PyObject *
 _socket_socket_if_nametoindex_impl(PySocketSockObject *self, PyObject *oname)
-/*[clinic end generated code: output=f7fc00511a309a8e input=662688054482cd46]*/
+/*[clinic end generated code: output=f7fc00511a309a8e input=242c01253c533053]*/
 {
 #ifdef MS_WINDOWS
     NET_IFINDEX index;