Remove useless pstrdup() calls.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 22 Oct 2025 20:22:52 +0000 (16:22 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 22 Oct 2025 20:22:52 +0000 (16:22 -0400)
The result of PLyUnicode_AsString is already palloc'd,
so pstrdup'ing it is just a waste of time and memory.
More importantly it might confuse people about whether
that's necessary.  Doesn't seem important enough to
back-patch, but we should fix it.  Spotted by Coverity.

src/pl/plpython/plpy_elog.c
src/pl/plpython/plpy_plpymodule.c

index f6d10045e5cea2128ff34fcfb38d49c961d746a8..a7c664f1ca193e22906260a6857a4ed1a2b31b62 100644 (file)
@@ -571,7 +571,7 @@ get_string_attr(PyObject *obj, char *attrname, char **str)
        val = PyObject_GetAttrString(obj, attrname);
        if (val != NULL && val != Py_None)
        {
-               *str = pstrdup(PLyUnicode_AsString(val));
+               *str = PLyUnicode_AsString(val);
        }
        Py_XDECREF(val);
 }
index 1f980b44b2a31a24fcb1788d81f4b95fcc4d96f6..89931612c5b19b001fe8881d4d1367843895d196 100644 (file)
@@ -369,7 +369,7 @@ PLy_quote_ident(PyObject *self, PyObject *args)
        return ret;
 }
 
-/* enforce cast of object to string */
+/* enforce cast of object to string (returns a palloc'd string or NULL) */
 static char *
 object_to_string(PyObject *obj)
 {
@@ -381,7 +381,7 @@ object_to_string(PyObject *obj)
                {
                        char       *str;
 
-                       str = pstrdup(PLyUnicode_AsString(so));
+                       str = PLyUnicode_AsString(so);
                        Py_DECREF(so);
 
                        return str;