]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
pythonmod: fix HANDLE_LEAK on pythonmod_init 1352/head
authorPetr Vaganov <petrvaganoff@gmail.com>
Tue, 23 Sep 2025 14:51:46 +0000 (19:51 +0500)
committerPetr Vaganov <petrvaganoff@gmail.com>
Tue, 23 Sep 2025 14:51:46 +0000 (19:51 +0500)
Found by the static analyzer Svace (ISP RAS).

Handle 'script_py' is created at pythonmod.c:436
by calling function 'fopen' and lost at pythonmod.c:457,465.

Signed-off-by: Petr Vaganov <petrvaganoff@gmail.com>
pythonmod/pythonmod.c

index e231ad0791724aa9199ae612a74b03ebb8c53b95..8cb023a512d72b96e1c8d609f4b9a8817072fdf3 100644 (file)
@@ -454,6 +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;
    }
    Py_XDECREF(fname);
@@ -462,6 +463,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;
    }