delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2019/06/18/22:03:58

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: Rod Pemberton <invalid AT lkntrgzxc DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: malloc() returns pointer to already allocated memory
Date: Tue, 18 Jun 2019 21:43:31 -0400
Organization: Aioe.org NNTP Server
Lines: 62
Message-ID: <qec3qv$1hdk$1@gioia.aioe.org>
References: <158e5d20-0a90-4beb-de48-da328379d8fb AT gmail DOT com>
<qe76u1$1kj8$1 AT gioia DOT aioe DOT org>
<f0b68226-f6f4-244a-6dd5-a8ecbabb584b AT gmail DOT com>
<qe79eb$1urs$1 AT gioia DOT aioe DOT org>
<qe7ar9$52r$1 AT gioia DOT aioe DOT org>
<qe7avt$52r$2 AT gioia DOT aioe DOT org>
<qe7bve$9ti$1 AT gioia DOT aioe DOT org>
<qe7f8g$oak$1 AT gioia DOT aioe DOT org>
<b035cc97-1261-e26e-2d3c-b3672928c9af AT gmail DOT com>
NNTP-Posting-Host: +15yR2JuBIwiofOqK4kSZw.user.gioia.aioe.org
Mime-Version: 1.0
X-Complaints-To: abuse AT aioe DOT org
X-Notice: Filtered by postfilter v. 0.9.2
Bytes: 4106
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

On Mon, 17 Jun 2019 18:33:09 +0200
"J.W. Jagersma (jwjagersma AT gmail DOT com) [via djgpp AT delorie DOT com]"
<djgpp AT delorie DOT com> wrote:

> On 2019-06-17 09:27, Rod Pemberton wrote:
> > The program seems to make a large number (on my machine) of small
> > allocations around ~268M (~0x0ff5d000) before a "clobber".  CWSDPR0
> > aborts with an error about page tables.  Could CWSDPMI be running
> > out of page tables? ...  Also, IIRC, PMODETSR doesn't use paging,
> > and it completes without any "clobbers".  The large number of
> > allocation might also be why no one noticed, or maybe this was a
> > known issue in the past but forgotten?  
> 
> The test program also works okay on hdpmi32, which doesn't use paging 
> either. In the program I'm working on, this clobbering does happen
> with hdpmi, and almost immediately on startup too, after allocating
> maybe 4MB or so. Hence why I'm not sure if this initial issue is
> related. Still I've traced the clobbering pointer down and it does
> seem to come straight from malloc.

a) did you guys dismiss the out of page tables thought?

b) how did you notice this issue originally?

c) is the "clobbering" actually causing corruption in your program?

d) are you worried that the large array malloc() moves to a memory
region where "clobbers" are not occurring or not being detected?

e) I'm not sure an actual "clobber" is occurring (see 2nd para below)


For d) I ask about this because when I attempted to modify the other
version to store all pointers in an array, so that I could free() all
of them. (Not enough memory.)  But, for a smaller array allocation, the
"clobbers" stopped occurring afterward, i.e., implying that the memory
location where the clobber occurs may be important.  The clobber
detected on my machine (check for two magic values) is always at about
the same memory address.  The program exits after the first detection.
The work to write out and flush the data to a disk file, i.e., not
tmpfile(), to avoid allocating a large array, was more than I was
interested in doing.  This is on MS-DOS v7.10 (Win98/SE).

For e), if I save the malloc'd pointer (twice) after the magic values
(two unique), i.e., 4 value sequence, then I fetch the saved pointer
upon a detected "clobber" matching both magic values, then write two
new values at the saved pointer location, no change of (two) values
occurs at (or anywhere around) the clobbered location.  I.e., the
original "clobber" would seems to be some type of mysterious
intermittent copying of data occurring ...  It doesn't seem to be
re-use, dual-use, dual-mapping, or overlap of memory regions.  A
possible guess would be that existing pages are sometimes being
re-used.  So, this may just be stale data.  It's possible that this
might be a hardware issue, not software, e.g., maybe processor MMU
instead of CWSDPMI.


Rod Pemberton
-- 
Once upon a time, many decades ago in a place far away, humble people
sought their freedom, and lost. "Ideas are bulletproof."

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019