Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WwWwT-0004uw-Pr for pgsql-odbc@arkaria.postgresql.org; Mon, 16 Jun 2014 13:27:21 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WwWwS-00076r-NZ for pgsql-odbc@arkaria.postgresql.org; Mon, 16 Jun 2014 13:27:20 +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 1WwWwR-00076l-TC for pgsql-odbc@postgresql.org; Mon, 16 Jun 2014 13:27:20 +0000 Received: from mout.kundenserver.de ([212.227.17.13]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1WwWwM-00081N-ND for pgsql-odbc@postgresql.org; Mon, 16 Jun 2014 13:27:17 +0000 Received: from ayaki.localdomain (106-69-159-150.dyn.iinet.net.au [106.69.159.150]) by mrelayeu.kundenserver.de (node=mreue105) with ESMTP (Nemesis) id 0MBBkT-1X4TYA348z-00ADZy; Mon, 16 Jun 2014 15:27:12 +0200 Message-ID: <539EF0AB.8040408@2ndquadrant.com> Date: Mon, 16 Jun 2014 21:27:07 +0800 From: Craig Ringer Organization: 2nd Quadrant User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: "pgsql-odbc@postgresql.org" Subject: PATCH: Fix minor unallocated memory access in msdtc_enlist.cpp X-Enigmail-Version: 1.6 Content-Type: multipart/mixed; boundary="------------070504070008000304050909" X-Provags-ID: V02:K0:ZPSe4/bd829bfMhjh+0wIRLiXgHaWqTy7P0w7yYKJ+K 4f+z7YENsEY6bzrihk7ALvJAi9RqiQS9xbMSvrlRieVsSp/uOa /+ku1cCQXp7TNiSroDeL+JluVX9Lc3ig/lPmnBAuzhR9yNdjyX MXUbTkMrwnlLi4brueJJ+8sfQ0H+TJmVtNZZh/CX+lFs/Jw0vW 6iRJXxjrGFSD3iCuBn9AizaVy7EpjA23M9fdOglH+LovWt3bdz KO27q8II5GmNU9slqXT/erdYw7/8uy6eS87FThmTgLYPbeuy10 SRLAEDMDNnALYI+cx+NthA/Sl110sy2g5JrcluXHIm4PhE+mIn JPcCD2NZO+UZ5v1EeYzcR7V/qCQJXMdAaqSljq4gx 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. --------------070504070008000304050909 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit The attached fixes a minor memory error in msdtc_enlist.cpp, see patch notes for explanation. It's in https://github.com/ringerc/psqlODBC.git in the topic branch return-deleted-memory-fix Unfortunately, it's not the bug I've been chasing. -- Craig Ringer http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services --------------070504070008000304050909 Content-Type: text/x-patch; name="0001-Fix-access-to-unallocated-memory-in-IAsyncPG.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Fix-access-to-unallocated-memory-in-IAsyncPG.patch" From db413945da7ef668b86811c0df507cb6931090a1 Mon Sep 17 00:00:00 2001 From: Craig Ringer Date: Mon, 16 Jun 2014 21:16:31 +0800 Subject: [PATCH] Fix access to unallocated memory in IAsyncPG IAsyncPG was deleting its self, then returning an instance variable by value. This is probably going to be safe pretty much all the time, but it's still a memory error, and DrMemory (a Windows valgrind-alike) complains about it: Error #4: UNADDRESSABLE ACCESS: reading 0x00b1b2b0-0x00b1b2b4 4 byte(s) # 0 pgenlista.dll!IAsyncPG::Release [c:\users\administrator\desktop\psqlodbc\msdtc_enlist.cpp:352] # 1 pgenlista.dll!CloseCommitThread [c:\users\administrator\desktop\psqlodbc\msdtc_enlist.cpp:971] # 2 MSVCR120D.dll!_callthreadstart [f:\dd\vctools\crt\crtw32\startup\thread.c:255] # 3 MSVCR120D.dll!_threadstart [f:\dd\vctools\crt\crtw32\startup\thread.c:237] # 4 KERNEL32.dll!BaseThreadInitThunk +0x11 (0x7768338a ) Note: @0:00:57.879 in thread 4516 Note: next higher malloc: 0x00b1b420-0x00b1b440 Note: 0x00b1b2b0-0x00b1b2b4 overlaps memory 0x00b1b2a0-0x00b1b390 that was freed here: Note: # 0 replace_operator_delete [d:\drmemory_package\common\alloc_replace.c:2524] Note: # 1 pgenlista.dll!IAsyncPG::`scalar deleting destructor' Note: # 2 pgenlista.dll!IAsyncPG::Release [c:\users\administrator\desktop\psqlodbc\msdtc_enlist.cpp:341] Note: # 3 pgenlista.dll!CloseCommitThread [c:\users\administrator\desktop\psqlodbc\msdtc_enlist.cpp:971] Note: # 4 MSVCR120D.dll!_callthreadstart [f:\dd\vctools\crt\crtw32\startup\thread.c:255] Note: # 5 MSVCR120D.dll!_threadstart [f:\dd\vctools\crt\crtw32\startup\thread.c:237] Note: # 6 KERNEL32.dll!BaseThreadInitThunk +0x11 (0x7768338a ) Note: instruction: mov 0x10(%eax) -> %eax This patch fixes the issue. --- msdtc_enlist.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/msdtc_enlist.cpp b/msdtc_enlist.cpp index ff40761..4795c75 100755 --- a/msdtc_enlist.cpp +++ b/msdtc_enlist.cpp @@ -337,8 +337,10 @@ ULONG STDMETHODCALLTYPE IAsyncPG::Release(void) SLOCK_ACQUIRE(); if (refcnt <=0) { + const int refcnt_copy = refcnt; mylog("delete %p\n", this); delete this; + return refcnt_copy; } else { -- 1.9.0 --------------070504070008000304050909 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 --------------070504070008000304050909--