From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#22526: 25.0.90; Crash starting gnus Date: Sun, 14 Feb 2016 07:41:18 +0200 Message-ID: <83povzzw5d.fsf@gnu.org> References: <56AFD88B.5040904@gmail.com> <87pow9cc0c.fsf@gnus.org> <83h9hkse78.fsf@gnu.org> <864mdk44q6.fsf@gmail.com> <83mvrcqli1.fsf@gnu.org> <86twlg2e69.fsf@gmail.com> <8360xv9ems.fsf@gnu.org> <8637sz7xmh.fsf@gmail.com> <83io1v7xcd.fsf@gnu.org> <83fuwx7vkv.fsf@gnu.org> <86fuwxk1l1.fsf@gmail.com> <837fi96mkq.fsf@gnu.org> <83vb5s6gas.fsf@gnu.org> <83d1s05zov.fsf@gnu.org> <83r3ggz2dt.fsf@gnu.org> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1455428631 14171 80.91.229.3 (14 Feb 2016 05:43:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 14 Feb 2016 05:43:51 +0000 (UTC) Cc: 22526@debbugs.gnu.org, andrewjmoreton@gmail.com To: fabrice.popineau@gmail.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Feb 14 06:43:36 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aUpT5-0001mz-CP for geb-bug-gnu-emacs@m.gmane.org; Sun, 14 Feb 2016 06:43:35 +0100 Original-Received: from localhost ([::1]:47685 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aUpT4-0002D7-Le for geb-bug-gnu-emacs@m.gmane.org; Sun, 14 Feb 2016 00:43:34 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44791) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aUpRe-00082s-CV for bug-gnu-emacs@gnu.org; Sun, 14 Feb 2016 00:42:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aUpRa-000459-9H for bug-gnu-emacs@gnu.org; Sun, 14 Feb 2016 00:42:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:47689) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aUpRa-00044w-5U for bug-gnu-emacs@gnu.org; Sun, 14 Feb 2016 00:42:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84) (envelope-from ) id 1aUpRZ-0000Ie-Um for bug-gnu-emacs@gnu.org; Sun, 14 Feb 2016 00:42:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 14 Feb 2016 05:42:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 22526 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 22526-submit@debbugs.gnu.org id=B22526.14554284881106 (code B ref 22526); Sun, 14 Feb 2016 05:42:01 +0000 Original-Received: (at 22526) by debbugs.gnu.org; 14 Feb 2016 05:41:28 +0000 Original-Received: from localhost ([127.0.0.1]:38464 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aUpR2-0000Hm-Gh for submit@debbugs.gnu.org; Sun, 14 Feb 2016 00:41:28 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:53650) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aUpR1-0000HZ-EW for 22526@debbugs.gnu.org; Sun, 14 Feb 2016 00:41:27 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aUpQv-0003rd-9d for 22526@debbugs.gnu.org; Sun, 14 Feb 2016 00:41:22 -0500 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:39566) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aUpQq-0003pn-GF; Sun, 14 Feb 2016 00:41:16 -0500 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:2413 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1aUpQp-000753-Lm; Sun, 14 Feb 2016 00:41:16 -0500 In-reply-to: <83r3ggz2dt.fsf@gnu.org> (message from Eli Zaretskii on Sun, 14 Feb 2016 00:11:58 +0200) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:113003 Archived-At: > Date: Sun, 14 Feb 2016 00:11:58 +0200 > From: Eli Zaretskii > Cc: 22526@debbugs.gnu.org, andrewjmoreton@gmail.com > > > From: Fabrice Popineau > > Date: Sat, 13 Feb 2016 22:35:57 +0100 > > Cc: andrewjmoreton@gmail.com, 22526@debbugs.gnu.org > > > > I think we need the DebPrint() trace of the problem to conclude. > > I think the patch I propose below will help in that. Fabrice didn't like my goto, so here's a version without that: diff --git a/src/w32heap.c b/src/w32heap.c index 00da86a..6047b19 100644 --- a/src/w32heap.c +++ b/src/w32heap.c @@ -652,15 +652,19 @@ mmap_alloc (void **var, size_t nbytes) { /* Now, commit pages for NBYTES. */ *var = VirtualAlloc (p, nbytes, MEM_COMMIT, PAGE_READWRITE); + if (*var == NULL) + p = *var; } if (!p) { - if (GetLastError () == ERROR_NOT_ENOUGH_MEMORY) + DWORD e = GetLastError (); + + if (e == ERROR_NOT_ENOUGH_MEMORY) errno = ENOMEM; else { - DebPrint (("mmap_alloc: error %ld\n", GetLastError ())); + DebPrint (("mmap_alloc: error %ld\n", e)); errno = EINVAL; } } @@ -700,6 +704,8 @@ mmap_realloc (void **var, size_t nbytes) /* We need to enlarge the block. */ if (memInfo.RegionSize < nbytes) { + void *old_ptr; + if (VirtualQuery (*var + memInfo.RegionSize, &m2, sizeof(m2)) == 0) DebPrint (("mmap_realloc: VirtualQuery error = %ld\n", GetLastError ())); @@ -715,31 +721,29 @@ mmap_realloc (void **var, size_t nbytes) MEM_COMMIT, PAGE_READWRITE); if (!p /* && GetLastError() != ERROR_NOT_ENOUGH_MEMORY */) { - DebPrint (("realloc enlarge: VirtualAlloc error %ld\n", + DebPrint (("realloc enlarge: VirtualAlloc (%p + %I64x, %I64x) error %ld\n", + *var, (uint64_t)memInfo.RegionSize, + (uint64_t)(nbytes - memInfo.RegionSize), GetLastError ())); - errno = ENOMEM; } + else + return *var; + } + /* Else we must actually enlarge the block by allocating a new + one and copying previous contents from the old to the new one. */ + old_ptr = *var; + + if (mmap_alloc (var, nbytes)) + { + CopyMemory (*var, old_ptr, memInfo.RegionSize); + mmap_free (&old_ptr); return *var; } else { - /* Else we must actually enlarge the block by allocating a - new one and copying previous contents from the old to the - new one. */ - void *old_ptr = *var; - - if (mmap_alloc (var, nbytes)) - { - CopyMemory (*var, old_ptr, memInfo.RegionSize); - mmap_free (&old_ptr); - return *var; - } - else - { - /* We failed to enlarge the buffer. */ - *var = old_ptr; - return NULL; - } + /* We failed to reallocate the buffer. */ + *var = old_ptr; + return NULL; } }