Skip to content

Commit

Permalink
SNOW-761669: fix memory leak in c logging (#1479)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-aling authored Mar 17, 2023
1 parent 1b437d5 commit 9008e2c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
4 changes: 4 additions & 0 deletions DESCRIPTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 11 additions & 5 deletions src/snowflake/connector/cpp/Logging/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/snowflake/connector/version.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 9008e2c

Please sign in to comment.