pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Inoue, Hiroshi <inoue@tpf.co.jp>
To: Jade Koskela <jkoskela0@gmail.com>
Cc: pgsql-odbc@postgresql.org <pgsql-odbc@postgresql.org>
Subject: Re: crash bug on closed connection
Date: Thu, 16 Oct 2014 04:23:38 +0900
Message-ID: <543EC9BA.1020901@tpf.co.jp> (raw)
In-Reply-To: <CAN5ZvqwLXs3z0pxAQOKDthLBdRkP_Md+bryiexdtAHtp0rFBng@mail.gmail.com>
References: <CAN5ZvqwcKmV7AoevuWJPfrN=rsqSzwDKRKXWhMPmCineggA_3Q@mail.gmail.com>
	<CAN5Zvqy6hsTBg2KcmA1zk1c+vvMNRmaJ5rRLTiBKoYSC=59HRA@mail.gmail.com>
	<CAN5ZvqzAi67VOnSXGtownVY57w-XPJxeBA4Q+BWfPTJVmQPRQw@mail.gmail.com>
	<CAN5ZvqyRro-wHxZoam=MoZh9Aa+0uwJ84bsOXKXb0jz8CyJqaA@mail.gmail.com>
	<CAN5ZvqwLXs3z0pxAQOKDthLBdRkP_Md+bryiexdtAHtp0rFBng@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-odbc>

Hi Jade,

Could you please try the attached patch?

regards,
Hiroshi Inoue

On 2014/10/15 14:38, Jade Koskela wrote:
> Here is the end of the log.
> I've done some debugging, when CC_send_query_append is called here, it
> correctly identifies that there was an error, and exits the function.
>
> res = CC_send_query_append(conn, self->stmt_with_params, qryi, qflag,
> SC_get_ancestor(self), appendq); (statement.c:2069)
>
> The result which is returned is not handled correctly (statement.c:2078)
>
> if (appendq)
> {
>      QResultClass    *qres, *nres;
>
>      if ( res->rstatus == PORES_EMPTY_QUERY && !res->next)
>          res = NULL;
>
>      for (qres = res; qres;)
>      {
>          if (qres->command && strnicmp(qres->command, fetch_cmd, 5) == 0)
>          {
>              res = qres;
>              break;
>          }
>          nres = qres->next;
>          if (nres && QR_get_notice(qres) != NULL)
>          {
>              if (QR_command_successful(nres) &&
>                  QR_command_nonfatal(qres))
>              {
>                  QR_set_rstatus(nres, PORES_NONFATAL_ERROR);
>              }
>              QR_add_notice(nres, QR_get_notice(qres));
>          }
>          qres->next = NULL;
>          QR_Destructor(qres);
>          qres = nres;
>      }
> }
>
> There is only a single result, with result.next == NULL.
> This part of the code calls the destructor on the only result, but res
> is still left pointing at it. After that fun things happen.
> It gets a long way before it actually crashes in
> Exec_with_parameters_resolved.

-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc

Attachments:

fix_a_crash.patch (text/x-diff, 3.5K) download diff --git a/connection.c b/connection.c index af985f2..7f73296 100644 --- a/connection.c +++ b/connection.c @@ -2808,6 +2808,7 @@ CC_send_query_append(ConnectionClass *self, const char *query, QueryInfo *qi, UD int maxlen, empty_reqs; BOOL ReadyToReturn = FALSE, + retDetermined = FALSE, query_completed = FALSE, beforeV2 = !(PROTOCOL_64(&self->connInfo) || PROTOCOL_74(&self->connInfo)), aborted = FALSE, @@ -3246,6 +3247,7 @@ inolog("Discarded the first SAVEPOINT\n"); else retres = cmdres; aborted = TRUE; + retDetermined = TRUE; } query_completed = TRUE; } @@ -3389,17 +3391,28 @@ mylog("!!! copydata len=%d\n", response_length);  cleanup: if (SOCK_get_errcode(self->sock) != 0) - { - if (0 == CC_get_errornumber(self)) - CC_set_error(self, CONNECTION_COMMUNICATION_ERROR, "Communication error while sending query", func); kill_conn = TRUE; - } if (kill_conn) - { CC_on_abort(self, CONN_DEAD); + + if (CONN_DOWN == self->status) + { + if (0 == CC_get_errornumber(self)) + CC_set_error(self, CONNECTION_COMMUNICATION_ERROR, "Communication error while sending query", func); retres = NULL; + aborted = TRUE; } - if (rollback_on_error && CC_is_in_trans(self) && !discard_next_savepoint) + /* +  * Break before being ready to return. +  */ + else if (!ReadyToReturn && +  !retDetermined) + retres = cmdres; + /* Issue rollback command if necessary */ + if (CONN_CONNECTED == self->status && +  rollback_on_error && +  CC_is_in_trans(self) && +  !discard_next_savepoint) { char cmd[64];  @@ -3421,12 +3434,6 @@ cleanup: CLEANUP_FUNC_CONN_CS(func_cs_count, self); #undef return /* - * Break before being ready to return. - */ - if (!ReadyToReturn) - retres = cmdres; - - /* * Cleanup garbage results before returning. */ if (cmdres && retres != cmdres && !used_passed_result_object) diff --git a/statement.c b/statement.c index da5abf5..98faadf 100644 --- a/statement.c +++ b/statement.c @@ -2077,12 +2077,17 @@ inolog("get_Result=%p %p %d\n", res, SC_get_Result(self), self->curr_param_resul */ if (appendq) { - QResultClass *qres, *nres; + QResultClass *qres, *pres, *nres;  - for (qres = res; qres;) + for (qres = res, pres = NULL; qres;) { if (qres->command && strnicmp(qres->command, fetch_cmd, 5) == 0) { + if (NULL != pres) + { + pres->next = NULL; + QR_Destructor(res); + } res = qres; break; } @@ -2096,8 +2101,7 @@ inolog("get_Result=%p %p %d\n", res, SC_get_Result(self), self->curr_param_resul } QR_add_notice(nres, QR_get_notice(qres)); } - qres->next = NULL; - QR_Destructor(qres); + pres = qres; qres = nres; } }

view thread (9+ messages)  latest in thread

Message-ID: <543EC9BA.1020901@tpf.co.jp>
Permalink:  ../543EC9BA.1020901@tpf.co.jp/
Also on:    postgresql.org/message-id/543EC9BA.1020901@tpf.co.jp

 ·  · 

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: inoue@tpf.co.jp, jkoskela0@gmail.com
  Subject: Re: crash bug on closed connection
  In-Reply-To: <543EC9BA.1020901@tpf.co.jp>
  References: <CAN5ZvqwcKmV7AoevuWJPfrN=rsqSzwDKRKXWhMPmCineggA_3Q@mail.gmail.com> <CAN5Zvqy6hsTBg2KcmA1zk1c+vvMNRmaJ5rRLTiBKoYSC=59HRA@mail.gmail.com> <CAN5ZvqzAi67VOnSXGtownVY57w-XPJxeBA4Q+BWfPTJVmQPRQw@mail.gmail.com> <CAN5ZvqyRro-wHxZoam=MoZh9Aa+0uwJ84bsOXKXb0jz8CyJqaA@mail.gmail.com> <CAN5ZvqwLXs3z0pxAQOKDthLBdRkP_Md+bryiexdtAHtp0rFBng@mail.gmail.com> <543EC9BA.1020901@tpf.co.jp>

* 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