X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: =?UTF-8?Q?Hans-Bernhard_Br=c3=b6ker?= Newsgroups: comp.os.msdos.djgpp Subject: Re: malloc() returns pointer to already allocated memory Date: Mon, 17 Jun 2019 23:31:08 +0200 Lines: 30 Message-ID: References: <158e5d20-0a90-4beb-de48-da328379d8fb AT gmail DOT com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: news.dfncis.de hKxyORMsNafl1zPem6f9NAJfd1NFy6xt5ulzAiB0kAsbmGFGiXQAXnTd7n Cancel-Lock: sha1:pu/75Ocj1u2YYzxxs3dg1A3lf8I= Openpgp: preference=signencrypt Autocrypt: addr=HBBroeker AT t-online DOT de; keydata= mQINBFu0018BEAC34KXenx8N+WV5OOk0YGkpMbnplVar2DFCNTIDEYA6d8S84mD2IB6/R29G gmE0NNKwt5C0vFvETkF1K8iZlI6TxzmtmTMqQk5lGWnxbv02EsSJu4drIwQssCfYoZ0y3XhL gUlZa2PrLvrEDI4HHeYCd87xagdsDX2+fBjMMBqnvYgyAU5UOhhG+R6s/8UtHlzyeJTLYXQQ zYcOFpcX3Q7BsDQukVAhh8RW2ss44TrNmyxbd63dWlG7ZgW525PaA02PsHVSLQz7uIg38S/a /wtB6VqzudvYwcekMyM/XSn/bxaUCHcGGfW81Nd2YtxH5HuqGddHuuQF2vFuVrF+8dA/rPdS xUd8ENaP5bueFWg2hWJb7m/uTGHOPNUeITDNLXpIElGZmqchb3j2kkzsebVlsa2BoYWdK4Aa 16gS0TzcgbAaPE5QRyKQlG/KEgUn6NzI2MSMJBilExtqJtw0fdXZzbOE/73XzfGNVCUk+M9l cXi5QLbYz0jSR2vvR/LXMYrnnl5jZ1Kc3ZNQU/8qaIMVreMybnDWaFYkFDscLPva51w04l6g VXDAxnV90YKJVzXJeTZhzNfa8MkNwKOmCTGew3ICP9sxIiodB/Qvgb9IkuYSqE+fGvl+IQzU W5/XhNH3VSyez4gJyluy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YYXkz22iCK7xKy9LzW fwuRH+vXIsv9PYpcooGL+Sn/T+fU+7L9xDvycflVrNmR05iDiOUYIE2X4dY6ox1X/wwxnMAy 1hcBLXn4PIzvApxfyt1xlXY0WATpyi+GqLagzDya0eXdCSoM8awgpKe+n8/aWQetF4WWhDPI mZFJJ7pa0jlUvkUH2raS7XOiOJWn9/ZjYoCQMfdY76Wk8L1TBmSHAN0vu9dC5jZfl/pVsspo fbK0pZZq45gj User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.1 In-Reply-To: <158e5d20-0a90-4beb-de48-da328379d8fb@gmail.com> Content-Language: en-US Bytes: 5895 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk Am 17.06.2019 um 02:27 schrieb J.W. Jagersma [via djgpp AT delorie DOT com]: > I ran into this issue with malloc(). It seems that, given enough > allocations, malloc() will eventually return a pointer into already > allocated memory. The problem with that claim is that it's just not correct. Your code is _not_ detecting what you claim it does. It really detects nothing at all. malloc() makes no guarantee whatsoever about the contents of the memory you get --- if you wanted a specific content, you know where to find calloc(), memset() and friends. Reading the contents of malloc()ed memory prior to writing to it yields, at best, indeterminate results. If done like in your test program (using pointers to a signed, multi-byte integer data type), is actually worse: it invokes undefined behaviour. So any conclusions drawn from looking at the value delivered by such read-outs, like yours, are automatically invalid. Please also keep in mind that this is DJGPP, targeting DOS. That's a single-user operating system with no need nor concept of security whatsoever. That means there's absolutely no particular reason for any part of the system, be that the DJGPP libc or run-time itself, the DPMI host, or the underlying DOS, to support security mechanisms intended to avoid, e.g., data leakage from one process to the other. In other words: a DOS DPMI host is well within its rights serving fresh pages whose contents just so happen to be copies of previously served ones. That's not the same as handing out the same page twice, nor does it constitute, by any stretch of the imagination, clobbering.