]> arthur.barton.de Git - bup.git/commitdiff
Fix memory leak in *stat calls in _helpers.c
authorAidan Hobson Sayers <aidanhs@cantab.net>
Fri, 10 Jan 2020 11:12:27 +0000 (11:12 +0000)
committerRob Browning <rlb@defaultvalue.org>
Sat, 25 Apr 2020 19:12:24 +0000 (14:12 -0500)
The Python documentation [0] indicates that an 'O' passed to
Py_BuildValue will have its refcount incremented. Since some elements of
the tuple created in stat_struct_to_py are pre-converted in C to
PyObjects, they already have a refcount of 1 - use 'N' to avoid
incrementing it and ensure Python can deallocate them correctly.

[0] https://docs.python.org/2/c-api/arg.html?highlight=py_buildvalue#c.Py_BuildValue

Signed-off-by: Aidan Hobson Sayers <aidanhs@cantab.net>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
(cherry picked from commit 3c57e31f68b3e68bf7053a628fcfd7ccccf217cd)
Tested-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/_helpers.c

index a03452a163c64dcd6acbfc1b05c9d5f5d99a74f7..d9c7ab8769bb2ffd8dcca4c1c1a42c2153ef2665 100644 (file)
@@ -103,7 +103,7 @@ static uint64_t htonll(uint64_t value)
     })
 
 
-// At the moment any code that calls INTGER_TO_PY() will have to
+// At the moment any code that calls INTEGER_TO_PY() will have to
 // disable -Wtautological-compare for clang.  See below.
 
 #define INTEGER_TO_PY(x) \
@@ -1384,7 +1384,7 @@ static PyObject *stat_struct_to_py(const struct stat *st,
     // compile time, but not (easily) the unspecified types, so handle
     // those via INTEGER_TO_PY().  Assumes ns values will fit in a
     // long.
-    return Py_BuildValue("OKOOOOOL(Ol)(Ol)(Ol)",
+    return Py_BuildValue("NKNNNNNL(Nl)(Nl)(Nl)",
                          INTEGER_TO_PY(st->st_mode),
                          (unsigned PY_LONG_LONG) st->st_ino,
                          INTEGER_TO_PY(st->st_dev),