From 9008e2c7f8bfba98c51d48f2f03b31e6ff52a531 Mon Sep 17 00:00:00 2001 From: Adam Ling Date: Fri, 17 Mar 2023 09:49:30 -0700 Subject: [PATCH] SNOW-761669: fix memory leak in c logging (#1479) --- DESCRIPTION.md | 4 ++++ src/snowflake/connector/cpp/Logging/logging.cpp | 16 +++++++++++----- src/snowflake/connector/version.py | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION.md b/DESCRIPTION.md index 64bd6329f..ccbce30c1 100644 --- a/DESCRIPTION.md +++ b/DESCRIPTION.md @@ -8,6 +8,10 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne # Release Notes +- v3.0.2(Unreleased) + + - Fixed a memory leak in the logging module of the Cython extension + - v3.0.1(February 28, 2023) - Improved the robustness of OCSP response caching to handle errors in cases of serialization and deserialization. diff --git a/src/snowflake/connector/cpp/Logging/logging.cpp b/src/snowflake/connector/cpp/Logging/logging.cpp index e43afe08d..b12aaf130 100644 --- a/src/snowflake/connector/cpp/Logging/logging.cpp +++ b/src/snowflake/connector/cpp/Logging/logging.cpp @@ -46,11 +46,17 @@ void Logger::log(int level, const char *path_name, const char *func_name, int li py::UniqueRef call_log(PyObject_GetAttrString(logger, "log")); // prepare keyword args for snow_logger - PyDict_SetItemString(keywords.get(), "level", Py_BuildValue("i", level)); - PyDict_SetItemString(keywords.get(), "path_name", Py_BuildValue("s", path_name)); - PyDict_SetItemString(keywords.get(), "func_name", Py_BuildValue("s", func_name)); - PyDict_SetItemString(keywords.get(), "line_num", Py_BuildValue("i", line_num)); - PyDict_SetItemString(keywords.get(), "msg", Py_BuildValue("s", msg)); + py::UniqueRef level_ref(Py_BuildValue("i", level)); + py::UniqueRef path_name_ref(Py_BuildValue("s", path_name)); + py::UniqueRef func_name_ref(Py_BuildValue("s", func_name)); + py::UniqueRef line_num_ref(Py_BuildValue("i", line_num)); + py::UniqueRef msg_ref(Py_BuildValue("s", msg)); + + PyDict_SetItemString(keywords.get(), "level", level_ref.get()); + PyDict_SetItemString(keywords.get(), "path_name", path_name_ref.get()); + PyDict_SetItemString(keywords.get(), "func_name", func_name_ref.get()); + PyDict_SetItemString(keywords.get(), "line_num", line_num_ref.get()); + PyDict_SetItemString(keywords.get(), "msg", msg_ref.get()); // call snow_logging.SnowLogger.log() PyObject_Call(call_log.get(), Py_BuildValue("()"), keywords.get()); diff --git a/src/snowflake/connector/version.py b/src/snowflake/connector/version.py index 9648021ea..0b12ea7d6 100644 --- a/src/snowflake/connector/version.py +++ b/src/snowflake/connector/version.py @@ -1,3 +1,3 @@ # Update this for the versions # Don't change the forth version number from None -VERSION = (3, 0, 1, None) +VERSION = (3, 0, 2, None)