* python/py-cmd.c (cmdpy_init): Decref 'ds_obj'.
[deliverable/binutils-gdb.git] / gdb / python / py-cmd.c
index 605c8c002eb797d939648b0045e0d01e649b5bd6..6516e1ff764d4b387bfacd0362cec9b162b8b017 100644 (file)
@@ -1,6 +1,6 @@
 /* gdb commands implemented in Python
 
-   Copyright (C) 2008-2012 Free Software Foundation, Inc.
+   Copyright (C) 2008-2013 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -68,7 +68,8 @@ struct cmdpy_object
 
 typedef struct cmdpy_object cmdpy_object;
 
-static PyTypeObject cmdpy_object_type;
+static PyTypeObject cmdpy_object_type
+    CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("cmdpy_object");
 
 /* Constants used by this module.  */
 static PyObject *invoke_cst;
@@ -103,7 +104,7 @@ cmdpy_destroyer (struct cmd_list_element *self, void *context)
 
   /* We allocated the name, doc string, and perhaps the prefix
      name.  */
-  xfree (self->name);
+  xfree ((char *) self->name);
   xfree (self->doc);
   xfree (self->prefixname);
 
@@ -206,12 +207,13 @@ cmdpy_function (struct cmd_list_element *command, char *args, int from_tty)
 
 /* Called by gdb for command completion.  */
 
-static char **
-cmdpy_completer (struct cmd_list_element *command, char *text, char *word)
+static VEC (char_ptr) *
+cmdpy_completer (struct cmd_list_element *command,
+                const char *text, const char *word)
 {
   cmdpy_object *obj = (cmdpy_object *) get_cmd_context (command);
   PyObject *textobj, *wordobj, *resultobj = NULL;
-  char **result = NULL;
+  VEC (char_ptr) *result = NULL;
   struct cleanup *cleanup;
 
   cleanup = ensure_python_env (get_current_arch (), current_language);
@@ -253,10 +255,10 @@ cmdpy_completer (struct cmd_list_element *command, char *text, char *word)
       if (len < 0)
        goto done;
 
-      result = (char **) xmalloc ((len + 1) * sizeof (char *));
       for (i = out = 0; i < len; ++i)
        {
          PyObject *elt = PySequence_GetItem (resultobj, i);
+         char *item;
 
          if (elt == NULL || ! gdbpy_is_string (elt))
            {
@@ -264,16 +266,15 @@ cmdpy_completer (struct cmd_list_element *command, char *text, char *word)
              PyErr_Clear ();
              continue;
            }
-         result[out] = python_string_to_host_string (elt);
-         if (result[out] == NULL)
+         item = python_string_to_host_string (elt);
+         if (item == NULL)
            {
              /* Skip problem elements.  */
              PyErr_Clear ();
              continue;
            }
-         ++out;
+         VEC_safe_push (char_ptr, result, item);
        }
-      result[out] = NULL;
     }
   else if (PyInt_Check (resultobj))
     {
@@ -320,7 +321,8 @@ gdbpy_parse_command_name (const char *name,
   struct cmd_list_element *elt;
   int len = strlen (name);
   int i, lastchar;
-  char *prefix_text, *prefix_text2;
+  char *prefix_text;
+  const char *prefix_text2;
   char *result;
 
   /* Skip trailing whitespace.  */
@@ -497,9 +499,12 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)
            {
              xfree (cmd_name);
              xfree (pfx_name);
+             Py_DECREF (ds_obj);
              return -1;
            }
        }
+
+      Py_XDECREF (ds_obj);
     }
   if (! docstring)
     docstring = xstrdup (_("This command is not documented."));
@@ -608,8 +613,7 @@ static PyMethodDef cmdpy_object_methods[] =
 
 static PyTypeObject cmdpy_object_type =
 {
-  PyObject_HEAD_INIT (NULL)
-  0,                             /*ob_size*/
+  PyVarObject_HEAD_INIT (NULL, 0)
   "gdb.Command",                 /*tp_name*/
   sizeof (cmdpy_object),         /*tp_basicsize*/
   0,                             /*tp_itemsize*/
@@ -667,6 +671,8 @@ gdbpy_string_to_argv (PyObject *self, PyObject *args)
     return NULL;
 
   py_argv = PyList_New (0);
+  if (py_argv == NULL)
+    return NULL;
 
   /* buildargv uses NULL to represent an empty argument list, but we can't use
      that in Python.  Instead, if ARGS is "" then return an empty list.
This page took 0.024837 seconds and 4 git commands to generate.