1. memory leak: ob_refcnt of new ref from (unknown) _mysql_Exception is 1 too high

    Report

    1
    static PyObject *_mysql_server_init(
    PyObject *self,
    PyObject *args,
    PyObject *kwargs) {
    static char *kwlist[] = {"args", "groups", NULL};
    char **cmd_args_c=NULL, **groups_c=NULL, *s;
    int cmd_argc=0, i, groupc;
    PyObject *cmd_args=NULL, *groups=NULL, *ret=NULL, *item;
    if (_mysql_server_init_done) {
    PyErr_SetString(_mysql_ProgrammingError,
    "already initialized");
    return NULL;
    }
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OO", kwlist,
    &cmd_args, &groups))
    return NULL;
    #if MYSQL_VERSION_ID >= 40000
    if (cmd_args) {
    if (!PySequence_Check(cmd_args)) {
    PyErr_SetString(PyExc_TypeError,
    "args must be a sequence");
    goto finish;
    }
    cmd_argc = PySequence_Size(cmd_args);
    if (cmd_argc == -1) {
    PyErr_SetString(PyExc_TypeError,
    "args could not be sized");
    goto finish;
    }
    cmd_args_c = (char **) PyMem_Malloc(cmd_argc*sizeof(char *));
    for (i=0; i< cmd_argc; i++) {
    item = PySequence_GetItem(cmd_args, i);
    s = get_string(item);
    Py_DECREF(item);
    if (!s) { goto finish; }
    cmd_args_c[i] = s;
    }
    }
    if (groups) {
    if (!PySequence_Check(groups)) {
    PyErr_SetString(PyExc_TypeError,
    "groups must be a sequence");
    goto finish;
    }
    groupc = PySequence_Size(groups);
    if (groupc == -1) {
    PyErr_SetString(PyExc_TypeError,
    "groups could not be sized");
    goto finish;
    }
    groups_c = (char **) PyMem_Malloc((1+groupc)*sizeof(char *));
    for (i=0; i< groupc; i++) {
    item = PySequence_GetItem(groups, i);
    s = get_string(item);
    Py_DECREF(item);
    if (!s) { goto finish; }
    groups_c[i] = s;
    }
    groups_c[groupc] = (char *)NULL;
    }
    /* even though this may block, don't give up the interpreter lock
    so that the server can't be initialized multiple times. */
    if (mysql_server_init(cmd_argc, cmd_args_c, groups_c)) {
    _mysql_Exception(NULL);
    goto finish;
    }
    #endif
    ret = Py_None;
    Py_INCREF(Py_None);
    _mysql_server_init_done = 1;
    finish:
    PyMem_Free(groups_c);
    PyMem_Free(cmd_args_c);
    return ret;
    }
    1. was expecting final owned ob_refcnt of new ref from (unknown) _mysql_Exception to be 0 since nothing references it but final ob_refcnt is refs: 1 owned

      found 24 similar trace(s) to this

    2. when considering value == (int)0 from _mysql.c:121

      taking False path

    3. when PyArg_ParseTupleAndKeywords() succeeds

      taking False path

    4. taking True path

    5. when considering range: -0x80000000 <= value <= -1

      taking False path

    6. when PySequence_Size() succeeds

    7. when considering range: -0x80000000 <= value <= -2

      taking False path

    8. when PyMem_Malloc() succeeds

    9. taking False path

    10. taking True path

    11. when considering range: 1 <= value <= 0x7fffffff

      taking False path

    12. when PySequence_Size() succeeds

    13. when considering range: 0 <= value <= 0x7fffffff

      taking False path

    14. when PyMem_Malloc() succeeds

    15. when considering range: 1 <= groupc <= 0x7fffffff

      taking True path

    16. when PySequence_GetItem() succeeds

    17. when taking False path

      calling tp_dealloc on new ref from PySequence_GetItem allocated at _mysql.c:316

    18. when treating unknown char * from _mysql.c:317 as non-NULL

      taking False path

    19. when considering groupc == (int)1 from _mysql.c:308

      taking False path

    20. when considering range: -0x80000000 <= value <= -1

      taking True path

    21. when _mysql_Exception() succeeds

      new ref from (unknown) _mysql_Exception was allocated at: _mysql_Exception(NULL);

    22. calling PyMem_Free on PyMem_Malloc allocated at _mysql.c:314

    23. calling PyMem_Free on PyMem_Malloc allocated at _mysql.c:292

  2. returning (PyObject*)NULL without setting an exception

    Report

    2
    static PyObject *_mysql_server_init(
    PyObject *self,
    PyObject *args,
    PyObject *kwargs) {
    static char *kwlist[] = {"args", "groups", NULL};
    char **cmd_args_c=NULL, **groups_c=NULL, *s;
    int cmd_argc=0, i, groupc;
    PyObject *cmd_args=NULL, *groups=NULL, *ret=NULL, *item;
    if (_mysql_server_init_done) {
    PyErr_SetString(_mysql_ProgrammingError,
    "already initialized");
    return NULL;
    }
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OO", kwlist,
    &cmd_args, &groups))
    return NULL;
    #if MYSQL_VERSION_ID >= 40000
    if (cmd_args) {
    if (!PySequence_Check(cmd_args)) {
    PyErr_SetString(PyExc_TypeError,
    "args must be a sequence");
    goto finish;
    }
    cmd_argc = PySequence_Size(cmd_args);
    if (cmd_argc == -1) {
    PyErr_SetString(PyExc_TypeError,
    "args could not be sized");
    goto finish;
    }
    cmd_args_c = (char **) PyMem_Malloc(cmd_argc*sizeof(char *));
    for (i=0; i< cmd_argc; i++) {
    item = PySequence_GetItem(cmd_args, i);
    s = get_string(item);
    Py_DECREF(item);
    if (!s) { goto finish; }
    cmd_args_c[i] = s;
    }
    }
    if (groups) {
    if (!PySequence_Check(groups)) {
    PyErr_SetString(PyExc_TypeError,
    "groups must be a sequence");
    goto finish;
    }
    groupc = PySequence_Size(groups);
    if (groupc == -1) {
    PyErr_SetString(PyExc_TypeError,
    "groups could not be sized");
    goto finish;
    }
    groups_c = (char **) PyMem_Malloc((1+groupc)*sizeof(char *));
    for (i=0; i< groupc; i++) {
    item = PySequence_GetItem(groups, i);
    s = get_string(item);
    Py_DECREF(item);
    if (!s) { goto finish; }
    groups_c[i] = s;
    }
    groups_c[groupc] = (char *)NULL;
    }
    /* even though this may block, don't give up the interpreter lock
    so that the server can't be initialized multiple times. */
    if (mysql_server_init(cmd_argc, cmd_args_c, groups_c)) {
    _mysql_Exception(NULL);
    goto finish;
    }
    #endif
    ret = Py_None;
    Py_INCREF(Py_None);
    _mysql_server_init_done = 1;
    finish:
    PyMem_Free(groups_c);
    PyMem_Free(cmd_args_c);
    return ret;
    }
    1. found 29 similar trace(s) to this

    2. when considering value == (int)0 from _mysql.c:121

      taking False path

    3. when PyArg_ParseTupleAndKeywords() succeeds

      taking False path

    4. taking True path

    5. when considering range: -0x80000000 <= value <= -1

      taking False path

    6. when PySequence_Size() succeeds

    7. when considering range: -0x80000000 <= value <= -2

      taking False path

    8. when PyMem_Malloc() succeeds

    9. taking False path

    10. taking True path

    11. when considering range: 1 <= value <= 0x7fffffff

      taking False path

    12. when PySequence_Size() succeeds

    13. when considering range: 0 <= value <= 0x7fffffff

      taking False path

    14. when PyMem_Malloc() succeeds

    15. when considering range: 1 <= groupc <= 0x7fffffff

      taking True path

    16. when PySequence_GetItem() succeeds

    17. when taking False path

      calling tp_dealloc on new ref from PySequence_GetItem allocated at _mysql.c:316

    18. when treating unknown char * from _mysql.c:317 as non-NULL

      taking False path

    19. when considering groupc == (int)1 from _mysql.c:308

      taking False path

    20. when considering range: -0x80000000 <= value <= -1

      taking True path

    21. when _mysql_Exception() succeeds

    22. calling PyMem_Free on PyMem_Malloc allocated at _mysql.c:314

    23. calling PyMem_Free on PyMem_Malloc allocated at _mysql.c:292

  3. dereferencing NULL (item->ob_refcnt) at _mysql.c:318

    Report

    3
    static PyObject *_mysql_server_init(
    PyObject *self,
    PyObject *args,
    PyObject *kwargs) {
    static char *kwlist[] = {"args", "groups", NULL};
    char **cmd_args_c=NULL, **groups_c=NULL, *s;
    int cmd_argc=0, i, groupc;
    PyObject *cmd_args=NULL, *groups=NULL, *ret=NULL, *item;
    if (_mysql_server_init_done) {
    PyErr_SetString(_mysql_ProgrammingError,
    "already initialized");
    return NULL;
    }
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OO", kwlist,
    &cmd_args, &groups))
    return NULL;
    #if MYSQL_VERSION_ID >= 40000
    if (cmd_args) {
    if (!PySequence_Check(cmd_args)) {
    PyErr_SetString(PyExc_TypeError,
    "args must be a sequence");
    goto finish;
    }
    cmd_argc = PySequence_Size(cmd_args);
    if (cmd_argc == -1) {
    PyErr_SetString(PyExc_TypeError,
    "args could not be sized");
    goto finish;
    }
    cmd_args_c = (char **) PyMem_Malloc(cmd_argc*sizeof(char *));
    for (i=0; i< cmd_argc; i++) {
    item = PySequence_GetItem(cmd_args, i);
    s = get_string(item);
    Py_DECREF(item);
    if (!s) { goto finish; }
    cmd_args_c[i] = s;
    }
    }
    if (groups) {
    if (!PySequence_Check(groups)) {
    PyErr_SetString(PyExc_TypeError,
    "groups must be a sequence");
    goto finish;
    }
    groupc = PySequence_Size(groups);
    if (groupc == -1) {
    PyErr_SetString(PyExc_TypeError,
    "groups could not be sized");
    goto finish;
    }
    groups_c = (char **) PyMem_Malloc((1+groupc)*sizeof(char *));
    for (i=0; i< groupc; i++) {
    item = PySequence_GetItem(groups, i);
    s = get_string(item);
    Py_DECREF(item);
    if (!s) { goto finish; }
    groups_c[i] = s;
    }
    groups_c[groupc] = (char *)NULL;
    }
    /* even though this may block, don't give up the interpreter lock
    so that the server can't be initialized multiple times. */
    if (mysql_server_init(cmd_argc, cmd_args_c, groups_c)) {
    _mysql_Exception(NULL);
    goto finish;
    }
    #endif
    ret = Py_None;
    Py_INCREF(Py_None);
    _mysql_server_init_done = 1;
    finish:
    PyMem_Free(groups_c);
    PyMem_Free(cmd_args_c);
    return ret;
    }
    1. when considering value == (int)0 from _mysql.c:121

      taking False path

    2. when PyArg_ParseTupleAndKeywords() succeeds

      taking False path

    3. taking True path

    4. when considering range: -0x80000000 <= value <= -1

      taking False path

    5. when PySequence_Size() succeeds

    6. when considering range: -0x80000000 <= value <= -2

      taking False path

    7. when PyMem_Malloc() succeeds

    8. taking False path

    9. taking True path

    10. when considering range: -0x80000000 <= value <= -1

      taking False path

    11. when PySequence_Size() succeeds

    12. when considering range: 0 <= value <= 0x7fffffff

      taking False path

    13. when PyMem_Malloc() succeeds

    14. when considering range: 1 <= groupc <= 0x7fffffff

      taking True path

    15. when PySequence_GetItem() fails

    16. found 1 similar trace(s) to this