]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- For #1352, align with the current Python<3 code.
authorYorgos Thessalonikefs <yorgos@nlnetlabs.nl>
Tue, 23 Sep 2025 15:31:55 +0000 (17:31 +0200)
committerYorgos Thessalonikefs <yorgos@nlnetlabs.nl>
Tue, 23 Sep 2025 15:31:55 +0000 (17:31 +0200)
doc/Changelog
pythonmod/pythonmod.c

index e26ef631347f5152ac9618268b64dfd834901bfc..2cab7bbb18bffe8f73b31b4073ddc94a4a4bcca8 100644 (file)
@@ -1,6 +1,7 @@
 23 September 2025: Yorgos
        - Merge #1352 from Petr Vaganov: pythonmod: fix HANDLE_LEAK on
          pythonmod_init.
+       - For #1352, align with the current Python<3 code.
 
 19 September 2025: Wouter
        - Fix to remove configure~ from release tarballs.
index 8cb023a512d72b96e1c8d609f4b9a8817072fdf3..7cd9a7543fdd8bac1845ad4739f05cf36582af42 100644 (file)
@@ -454,8 +454,7 @@ int pythonmod_init(struct module_env* env, int id)
    if(PyDict_SetItemString(pe->data, "script", fname) < 0) {
        log_err("pythonmod: could not add item to dictionary");
        Py_XDECREF(fname);
-       fclose(script_py);
-       goto python_init_fail;
+       goto fail_close_file;
    }
    Py_XDECREF(fname);
    Py_XINCREF(pe->data);  /* reference will be stolen below */
@@ -463,8 +462,7 @@ int pythonmod_init(struct module_env* env, int id)
        log_err("pythonmod: could not add mod_env object");
        Py_XDECREF(pe->data);  /* 2 times, here and on python_init_fail; */
                               /* on failure the reference is not stolen */
-       fclose(script_py);
-       goto python_init_fail;
+       goto fail_close_file;
    }
 
    if (PyRun_SimpleFile(script_py, pe->fname) < 0) {
@@ -495,31 +493,15 @@ int pythonmod_init(struct module_env* env, int id)
       flen = (size_t)ftell(script_py);
       fstr = malloc(flen+1);
       if(!fstr) {
-             log_err("malloc failure to print parse error");
-
-/* close the file */
-#if PY_MAJOR_VERSION < 3
-             Py_XDECREF(PyFileObject);
-#else
-             fclose(script_py);
-#endif
-
-             goto python_init_fail;
+               log_err("malloc failure to print parse error");
+               goto fail_close_file;
       }
       fseek(script_py, 0, SEEK_SET);
       if(fread(fstr, flen, 1, script_py) < 1) {
-             log_err("file read failed to print parse error: %s: %s",
+               log_err("file read failed to print parse error: %s: %s",
                pe->fname, strerror(errno));
-             free(fstr);
-
-/* close the file */
-#if PY_MAJOR_VERSION < 3
-             Py_XDECREF(PyFileObject);
-#else
-             fclose(script_py);
-#endif
-
-             goto python_init_fail;
+               free(fstr);
+               goto fail_close_file;
       }
       fstr[flen] = 0;
       /* we compile the string, but do not run it, to stop side-effects */
@@ -529,21 +511,13 @@ int pythonmod_init(struct module_env* env, int id)
 #endif
 
       log_py_err();
-
-/* close the file */
-#if PY_MAJOR_VERSION < 3
-      Py_XDECREF(PyFileObject);
-#else
-      fclose(script_py);
-#endif
-
 #if PY_MAJOR_VERSION <= 2 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 9)
       /* no cleanup needed for python before 3.9 */
 #else
       /* cleanup for python 3.9 and newer */
       free(fstr);
 #endif
-      goto python_init_fail;
+      goto fail_close_file;
    }
 
 /* close the file */
@@ -604,6 +578,13 @@ int pythonmod_init(struct module_env* env, int id)
    PyGILState_Release(gil);
    return 1;
 
+fail_close_file:
+#if PY_MAJOR_VERSION < 3
+   Py_XDECREF(PyFileObject);
+#else
+   fclose(script_py);
+#endif
+
 python_init_fail:
    Py_XDECREF(pe->module);
    Py_XDECREF(pe->dict);