tds-fdw / tds_fdw

A PostgreSQL foreign data wrapper to connect to TDS databases (Sybase and Microsoft SQL Server)
Other
357 stars 99 forks source link

after 7 time run same plsql function, tds_fdw crash #280

Open Linreg-gmx-net opened 3 years ago

Linreg-gmx-net commented 3 years ago

Issue report

when you run an plpsql function 7 times than the fdw crash. After 5th time the query plan is cashed and not full initialized as before. Then free allocation from festate->query lead to sementation fault.

in psql you can run a query 1000 times, but in an plpsql function it run only 7 times.

In file tds_fdw.c in void tdsEndForeignScan(ForeignScanState *node) Line 1934:

    if (festate->query)
    {
            pfree(festate->query); <== this crash process, comment it and it run fine
    }

festate->query it initialized on line 1324

festate->query = strVal(list_nth(fsplan->fdw_private ....

But this allocate no new memory. it get only the list-pointer. something is missing, like an shutdown function to free option_set memory.

Operating system

OpenSuse 15.2

Version of tds_fdw

2.0.2 Name | Version | Schema | Beschreibung --------------+---------+------------+----------------------------------------------------------------------------------- file_fdw | 1.0 | public | foreign-data wrapper for flat file access hstore | 1.3 | public | data type for storing sets of (key, value) pairs plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language postgres_fdw | 1.0 | public | foreign-data wrapper for remote PostgreSQL servers tablefunc | 1.0 | public | functions that manipulate whole tables, including crosstab tds_fdw | 2.0.2 | public | Foreign data wrapper for querying a TDS database (Sybase or Microsoft SQL Server) uuid-ossp | 1.0 | public | generate universally unique identifiers (UUIDs)

ESC[33mcommit 012350f68cea6159d1667b30d939afed05399e4aESC[m HEADESC[33m (ESC[mESC[1;36mHEAD -> ESC[mESC[1;32mmasterESC[mESC[33m, ESC[mESC[1;31morigin/masterESC[mESC[33m, ESC[mESC[1;31morigin/HEADESC[mESC[33m) > Author: RAFAELDEV2016 rafael.dev2016@gmail.com Date: Fri Nov 27 21:44:34 2020 +0100

Version of PostgreSQL

PostgreSQL 10.16 on x86_64-suse-linux-gnu, compiled by gcc (SUSE Linux) 7.5.0, 64-bit

Version of FreeTDS

freetds-config-1.1.36-lp152.1.1.x86_64 freetds-tools-1.1.36-lp152.1.1.x86_64 freetds-devel-1.1.36-lp152.1.1.x86_64

Logs

Sentences, data structures, data

lobettini commented 3 months ago

Hi, i have the exact same problem. Did you find a way to fix it or a workarround? Thanks