pg.ddx.io pgsql-odbc@postgresql.org mailing list archive
help / color / mirror / Atom feed From: blegay <b.legay@ac-consulting.fr>
To: pgsql-odbc@postgresql.org
Subject: Re: psqlodbc 09.01.0200 - OS X 10.6 - memory leak ?
Date: Mon, 8 Apr 2013 04:05:27 -0700 (PDT)
Message-ID: <1365419127118-5751192.post@n5.nabble.com> (raw )
In-Reply-To: <1365232946306-5751040.post@n5.nabble.com >
References: <1365106058286-5750832.post@n5.nabble.com >
<1365133737522-5750890.post@n5.nabble.com >
<1365232946306-5751040.post@n5.nabble.com >
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-odbc>
Hi,
I have been able to reproduce and isolate the problem in a C code...
It is related to the SQLNumResultCols ODBC function after a call to
SQLMoreResults which does not return any lines (it is an INSERT statement).
Can anybody help ?
//
// main.c
// odbctest
//
// Created by Bruno LEGAY on 05/04/13.
// Copyright 2013 A&C Consulting. All rights reserved.
//
#include <stdio.h>
#include <sql.h>
#include <sqlext.h>
#include <string.h>
#include <math.h>
/*
* see Retrieving ODBC Diagnostics
* for a definition of extract_error().
*/
static void extract_error(
char *fn,
SQLHANDLE handle,
SQLSMALLINT type);
int main (int argc, const char * argv[])
{
SQLHENV env;
SQLHDBC dbc;
SQLHSTMT stmt;
SQLRETURN ret;
SQLCHAR outstr[1024];
SQLSMALLINT infos;
SQLSMALLINT resultlen;
double iters;
SQLUSMALLINT getFuncRes;
SQLSMALLINT nbcols;
SQLLEN rowcount;
/* Allocate an environment handle */
SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
/* We want ODBC 3 support */
SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
/* Allocate a connection handle */
SQLAllocHandle(SQL_HANDLE_DBC, env, &dbc);
/* Connect to the DSN oncdPostgreSQL_Unicode */
/*ret = SQLDriverConnect(dbc, NULL,
"DSN=oncdPostgreSQL_Unicode;UID=postgres;PWD=postgres;", SQL_NTS,
outstr, sizeof(outstr), &outstrlen,
SQL_DRIVER_COMPLETE);*/
SQLCHAR* dsn = (SQLCHAR*)"oncdPostgreSQL_Unicode";
SQLCHAR* uid = (SQLCHAR*)"postgres";
SQLCHAR* auth = (SQLCHAR*)"postgres";
ret = SQLConnect(dbc, dsn, SQL_NTS, uid, SQL_NTS, auth, SQL_NTS);
/*
SQLWCHAR* dsn = "oncdPostgreSQL_Unicode";
SQLWCHAR* uid = "postgres";
SQLWCHAR* auth = "postgres";
ret = SQLConnectW(dbc, dsn, SQL_NTS, uid, SQL_NTS, auth, SQL_NTS);
*/
//strcpy((char*)dsn,"oncdPostgreSQL_Unicode");
//strcpy((char*)uid,"postgres");
//strcpy((char*)auth,"postgres");
//dsn = "oncdPostgreSQL_Unicode";
//uid = "postgres";
//auth = "postgres";
//ret = SQLConnectW(dbc, (SQLWCHAR*)dsn, SQL_NTS, (SQLWCHAR*)uid,
SQL_NTS, (SQLWCHAR*)auth, SQL_NTS);
//ret = SQLConnectW(dbc, (SQLCHAR*)"oncdPostgreSQL_Unicode", SQL_NTS,
(SQLCHAR*)"postgres", SQL_NTS, (SQLCHAR*)"postgres", SQL_NTS);
if (SQL_SUCCEEDED(ret)) {
printf("Connected\n");
ret = SQLGetInfo(dbc,SQL_ASYNC_MODE,&infos, sizeof(infos),
&resultlen);
ret =
SQLSetConnectAttr(dbc,SQL_ATTR_AUTOCOMMIT,(void*)SQL_AUTOCOMMIT_ON,SQL_IS_INTEGER);
printf("Returned connection string was:\n\t%s\n", outstr);
if (ret == SQL_SUCCESS_WITH_INFO) {
printf("Driver reported the following diagnostics\n");
extract_error("SQLDriverConnect", dbc, SQL_HANDLE_DBC);
}
//SQLCHAR* sqlStatement;
//strcpy (sqlStatement,"INSERT INTO bug_127330 (urn,app,ts) VALUES
(?,'C',clock_timestamp())");
SQLCHAR* sqlStatement = (SQLCHAR*)"INSERT INTO bug_127330
(urn,app,ts) VALUES (?,'C',clock_timestamp())";
printf("Statement : %s\n",sqlStatement);
while (1) {
iters++;
//printf("iters : %d\n",iters);
/* Allocate a statement handle */
ret = SQLAllocHandle(SQL_HANDLE_STMT, dbc, &stmt);
//printf("AllocHandle : %i \n",ret);
if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) {
// infinite loop...
SQLGetFunctions(dbc,SQL_API_SQLPUTDATA,&getFuncRes);
// SQL FIXER PARAMETRE($vl_iters;SQL Paramètre entrée)
//ret = SQLBindParameter(stmt, 1, SQL_PARAM_INPUT,
// SQL_C_SLONG, SQL_INTEGER, 0, 0,
// &iters, sizeof(iters), NULL);
// SQL EXECUTER($vt_sql)
ret = SQLPrepare(stmt, sqlStatement, SQL_NTS);
ret = SQLBindParameter(stmt, 1, SQL_PARAM_INPUT,
SQL_C_DOUBLE, SQL_DOUBLE, 7, 0,
&iters, sizeof(iters), NULL);
ret = SQLExecute(stmt);
ret = SQLNumResultCols(stmt,&nbcols);
ret = SQLMoreResults(stmt);
//=======================================
// This call will generate leaks !!!
ret = SQLNumResultCols(stmt,&nbcols);
//=======================================
ret = SQLRowCount(stmt,&rowcount);
if (fmod(iters,1000) == 0)
printf("Insert data OK : %g\n",iters);
// SQL ANNULER CHARGEMENT
//ret = SQLFreeStmt(stmt, SQL_RESET_PARAMS);
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
} else {
printf("Error Allocating Handle: %d\n", ret);
}
}
SQLDisconnect(dbc); /* disconnect from driver */
printf("Disconnected\n");
} else {
fprintf(stderr, "Failed to connect\n");
extract_error("SQLDriverConnect", dbc, SQL_HANDLE_DBC);
}
/* free up allocated handles */
SQLFreeHandle(SQL_HANDLE_DBC, dbc);
SQLFreeHandle(SQL_HANDLE_ENV, env);
return 0;
}
static void extract_error(
char *fn,
SQLHANDLE handle,
SQLSMALLINT type) {
SQLINTEGER i = 0;
SQLINTEGER native;
SQLCHAR state[ 7 ];
SQLCHAR text[256];
SQLSMALLINT len;
SQLRETURN ret;
fprintf(stderr,
"\n"
"The driver reported the following diagnostics whilst running "
"%s\n\n",
fn);
do
{
ret = SQLGetDiagRec(type, handle, ++i, state, &native, text,
sizeof(text), &len );
if (SQL_SUCCEEDED(ret))
printf("%s:%i:%i:%s\n", state, i, native, text);
}
while( ret == SQL_SUCCESS );
}
<http://postgresql.1045698.n5.nabble.com/file/n5751192/with_leak.png ;
<http://postgresql.1045698.n5.nabble.com/file/n5751192/without_leak.png ;
--
View this message in context: http://postgresql.1045698.n5.nabble.com/psqlodbc-09-01-0200-OS-X-10-6-memory-leak-tp5750832p5751192....
Sent from the PostgreSQL - odbc mailing list archive at Nabble.com.
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
view thread (5+ messages) latest in thread
Message-ID: <1365419127118-5751192.post@n5.nabble.com>
Permalink: ../1365419127118-5751192.post@n5.nabble.com/
Also on: postgresql.org/message-id/1365419127118-5751192.post@n5.nabble.com
copy link · copy postgr.es
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-odbc@postgresql.org
Cc: b.legay@ac-consulting.fr
Subject: Re: psqlodbc 09.01.0200 - OS X 10.6 - memory leak ?
In-Reply-To: <1365419127118-5751192.post@n5.nabble.com>
References: <1365106058286-5750832.post@n5.nabble.com> <1365133737522-5750890.post@n5.nabble.com> <1365232946306-5751040.post@n5.nabble.com> <1365419127118-5751192.post@n5.nabble.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox