Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XeUAl-0005Vh-O6 for pgsql-odbc@arkaria.postgresql.org; Wed, 15 Oct 2014 19:23:47 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XeUAl-0002cK-6x for pgsql-odbc@arkaria.postgresql.org; Wed, 15 Oct 2014 19:23:47 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XeUAk-0002bk-7f for pgsql-odbc@postgresql.org; Wed, 15 Oct 2014 19:23:46 +0000 Received: from sd.tpf.co.jp ([210.161.239.34]) by makus.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XeUAg-0006Yu-41 for pgsql-odbc@postgresql.org; Wed, 15 Oct 2014 19:23:44 +0000 Received: (qmail 2612 invoked from network); 15 Oct 2014 19:23:37 -0000 X-Authentication: inoue was authenticated by sd.tpf.co.jp at 15 Oct 2014 19:23:37 -0000 Received: from unknown (HELO ?192.168.1.8?) (110.5.29.219) by sd.tpf.co.jp with SMTP; 15 Oct 2014 19:23:37 -0000 Message-ID: <543EC9BA.1020901@tpf.co.jp> Date: Thu, 16 Oct 2014 04:23:38 +0900 From: "Inoue, Hiroshi" User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.1.2 MIME-Version: 1.0 To: Jade Koskela CC: "pgsql-odbc@postgresql.org" Subject: Re: crash bug on closed connection References: In-Reply-To: Content-Type: multipart/mixed; boundary="------------040801060004090103070309" X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-odbc Precedence: bulk Sender: pgsql-odbc-owner@postgresql.org This is a multi-part message in MIME format. --------------040801060004090103070309 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit 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. --------------040801060004090103070309 Content-Type: text/x-diff; name="fix_a_crash.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="fix_a_crash.patch" 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; } } --------------040801060004090103070309 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-odbc --------------040801060004090103070309--