Browse Source

Fix bad allocation and free on repr.

Stefano Cossu 1 year ago
parent
commit
15c8029475
1 changed files with 3 additions and 1 deletions
  1. 3 1
      cpython/py_term.h

+ 3 - 1
cpython/py_term.h

@@ -305,8 +305,9 @@ Term_repr (PyObject *self)
     TermObject *term_obj = (TermObject *)self;
     LSUP_Term *term = term_obj->ob_struct;
     char *term_repr_ptn = "<%s @%p> '%s'";
-    char *term_nt;
+    char *term_nt = NULL;
     if (UNLIKELY (nt_codec.encode_term (term, NULL, &term_nt) != LSUP_OK)) {
+        free (term_nt);
         PyErr_SetString (PyExc_ValueError, "Error serializing term.");
         return NULL;
     }
@@ -319,6 +320,7 @@ Term_repr (PyObject *self)
     sprintf (
             term_repr, term_repr_ptn,
             self->ob_type->tp_name, term_obj, term_nt);
+    free (term_nt);
 
     PyObject *result = PyUnicode_FromString (term_repr);
     free (term_repr);