Project

General

Profile

Bug #4974

Memory leak in SPI functions

Added by Álvaro Herrera over 18 years ago. Updated over 18 years ago.

Status:
Closed
Priority:
High
Assignee:
Álvaro Herrera
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
fixed

Description

This can be reproduced with the following function:

create or replace function test_spi_1(int) returns int language plphp as $$
    $query = "select generate_series(1, $argsr0)";
    $result = spi_exec($query);

    $msg = "processed: " . spi_processed($result) . " ";
    $msg .= "status: " . spi_status($result);

    pg_raise('notice', $msg);

    $a = 0;
    while ($row = spi_fetch_row($result))
        $a += $row['generate_series'];

    pg_raise('notice', "total sum is " . $a);

    return $a;
$$;

Setting a memory limit of 3M on my i686-linux machine crashes with this call:

select test_spi_1(142857);
NOTICE:  plphp: processed: 142857 status: SPI_OK_SELECT
ERROR:  plphp: Allowed memory size of 3145728 bytes exhausted (tried to allocate 12 bytes)

On a Turion64 machine it consumes much more memory, as the same example makes it crash with an 8M memory limit (which doesn't make the i686 machine crash.)

Also available in: Atom PDF