⚡ Sangsakala Proxy 🏠 Home
Skip to content

Memory leak in source_putdata/source_getdata #95

Open

Description

@fairyfar

I noticed that source_putdata function in ext/pgsource.c

...
else {                /* copy is done */
    PGresult *result; /* final result of the operation */

    Py_BEGIN_ALLOW_THREADS;
    result = PQgetResult(self->pgcnx->cnx);
    Py_END_ALLOW_THREADS;

    if (PQresultStatus(result) == PGRES_COMMAND_OK) {
        char *tmp;
        long num_rows;

        tmp = PQcmdTuples(result);
        num_rows = tmp[0] ? atol(tmp) : -1;
        ret = PyLong_FromLong(num_rows);
    }
    else {
        if (!errormsg)
            errormsg = PQerrorMessage(self->pgcnx->cnx);
        PyErr_SetString(PyExc_IOError, errormsg);
        ret = NULL;
    }

    PQclear(self->result);
    self->result = NULL;
    self->result_type = RESULT_EMPTY;
}

The return result of PQgetResult does not use PQclear to release memory, which may lead to a memory leak.
The same issue in source_getdata.

Activity

  1. self-assigned this
    on Oct 19, 2026
  2. Cito commented on Oct 19, 2026

    @Cito
    Member

    Thank you for reporting this issue! I think you're correct and this is in fact a memory leak.

    There will be a new release soon that will include the fix and support for Python 3.15. I you have more things that should be fixed in this release, please report them as well.

  3. fairyfar commented on Oct 26, 2026

    @fairyfar
    Author

    3. Thank you for reporting this issue! I think you're correct and this is in fact a memory leak.
    There will be a new release soon that will include the fix and support for Python 3.15. I you have more things that should be fixed in this release, please report them as well.

    Nothing else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions