X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f X-Recipient: djgpp AT delorie DOT com X-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:openpgp:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=ei2+Ev9f7TwDDdZlBd+nlDy93Ac/GJXfL66Q9hobClM=; b=olwStKkUgYk+FpvnX0J81XLhJdSOi+shscEky5WgjQxn4ZuOHPvbUREPy54rplFfs5 dKq7D4jRe01m0F0eQUp/M77BQivgyilKdLNuIoFhErGphp7zBzLDEbNl4XJTauL5BcR7 5sM8qEobJGYV0XXYdT+DFZ01uLsw+/yc/zCAgs6ZJcPBdCMSChMK3zp1M0p61NnhRMAD HQOJSoJmWg0Pkyh3n7tRfdk6SICPLJBuqkVDEF4C0p88t8KMeZQhQ8R5mvtQz/YHHXzq NMRR7ZLlF0tU6RZc/Nd5vT1UArpL5h64pzs2uNcA0IxpZsTIl31PKaKDPtGuUUUXBVpf RZdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=ei2+Ev9f7TwDDdZlBd+nlDy93Ac/GJXfL66Q9hobClM=; b=foGWIfQOhM6RnGRQUx9BSIYDCyUWrfvTwAUr1PMNiHdPM0Jz6djH1iyse8sgWYqiJJ riqSfzM+h9FA2CcKi53X10jvi7Gh7ulObEJbr9BGEfzPoywfFEvONJkPL6AY6ppUNLL/ kqlJyeo35na4NrxU7dRtbpn0TI9A5QgixWgrietPUt0OpTynnvY5rpaDfKR7A/xaNjwK WIQgvBFAPUxiuVAwMVDN9pCpCOriAO+EtwKgovSI0+mvxvoJNHJWwkHCleUz/kmPv7WP 4LGbWgkN/3AFzDmCneGgQV/iukcDs2+iL9g9n9bKbLqSgRTZFHiulnCfLUgfOIrn7tM0 pwlg== X-Gm-Message-State: APjAAAVcjdGfe5kxPpbvvaqtHDh/GDbmApuwKoqvvzmKpBwgaoAGoP/d i41kXsjTFtVxn+TBCev5SDzvmqCq X-Google-Smtp-Source: APXvYqxfbOhkNmz7RkS5nvplWRzHQUqw1xzDbn2UpmiVSe1DDw8q+mMDiM9UHOm4ylSYzs43VIYZEQ== X-Received: by 2002:a17:907:384:: with SMTP id ss4mr78695482ejb.166.1560788808772; Mon, 17 Jun 2019 09:26:48 -0700 (PDT) Subject: Re: malloc() returns pointer to already allocated memory To: djgpp AT delorie DOT com References: <158e5d20-0a90-4beb-de48-da328379d8fb AT gmail DOT com> From: "J.W. Jagersma (jwjagersma AT gmail DOT com) [via djgpp AT delorie DOT com]" Openpgp: id=D1694EA4DA1338AF4905293BA5102F469FA45960 Autocrypt: addr=jwjagersma AT gmail DOT com; prefer-encrypt=mutual; keydata= mJMEWlMYlBMJKyQDAwIIAQENBAMEORD9eiW30pI0XzJbuE7/4WF3ZyEOkpRgrmZnpTRmzXMW z22N+2YrczEM+q+NzM/wn8XOVH4hZ7eSaUsLT86YLS+gF/F44IbRZVCHxdrL+qSQQ0SafwDM Aaddx2azX+6MtlFO2B6oDbCHT7Nn5oQi3IgR+pgBzaCkfxyOnU1wjvO0JEouVy4gSmFnZXJz bWEgPGp3amFnZXJzbWFAZ21haWwuY29tPojQBBMTCgA4FiEE0WlOpNoTOK9JBSk7pRAvRp+k WWAFAlpTGJQCGwMFCwkIBwIGFQgJCgsCBBYCAwECHgECF4AACgkQpRAvRp+kWWA3xAH/WIBG sLngyIrTsn5uKz4JygtlCfjMRRSwl3/UIaW96VvIM/wUyzHl+vlyLmuclOjAiTVia/Js03Ar zB9iCHZQ0QH/W8cRwHjRNZRukU2IR8eqoGsl6hTUrrAAOKOVO04wrjO4jGDHg3Sw2GxBx7Md mD0QRId/gFwR/1UWS0jBdSUWC7iXBFpTGJQSCSskAwMCCAEBDQQDBFipNF/RUEAer/hhT6yJ 5no1ZLAZgpypvWZ3xJSrBKmcDTaOmNKNRrw1dNtSZ6M6wYcBmtCq7uvR5iiGyK3nD+olwe7a 4WDkhEEvbmdAYl2LnBsYeyruoW+N+KiMalvf9SphDmBi2NwdSZ1IhnBpxlUns8jqlgZGvG1G xE1sleq7AwEKCYi4BBgTCgAgFiEE0WlOpNoTOK9JBSk7pRAvRp+kWWAFAlpTGJQCGwwACgkQ pRAvRp+kWWBnyAH+JLrW/cK2aVDvq2nxn471opBgHyExzMi0hvbuy8BjyEt+AfL0RNCFcdds CQakIGDv5k69TAgOftECgASwv6CG5wH8D3jnksh6YvYMf0hCBlSfwJ5ehIeqQTj0m2410RgC KWywqmfU1X5YVXgmuXatRNgV/ggXS2Q7GnSP/StQzlh3sQ== Message-ID: Date: Mon, 17 Jun 2019 18:25:42 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit 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 On 2019-06-17 07:05, Rod Pemberton wrote: > Second problem is you don't call memset() prior to using memory, nor > free() after you're done using it. Of course, calling memset() would > prevent your method of "clobber" detection from working. But, not > calling memset() means you don't know if the magic clobber value is: > a) from you setting it within your program, or > b) from some random garbage values in memory. The probability of one 32-bit memory address having a particular value is 1/(2^32), so about 1 in 4 billion. for a machine with, say, 256MB memory, you'd expect to find this value roughly once every 64 runs (IF all memory is initialized to perfectly random values, which it isn't. You're far more likely to find all ones or all zeroes on a clean boot). Clearly that isn't the case here, the clobber is detected every single time. Clearing allocated memory by memset(), you wouldn't be able to find clobbered memory unless you kept track of all allocated pointers. Which requires a large table... allocated with malloc(). If malloc is bugged, you'd end up clobbering this table too. Initially I did use a fixed magic value, but that causes false-positives on subsequent runs since memory isn't reset to zero. Using randomly-sized allocations turned out to be unnecessary since it happens with fixed size allocations too. > Finally, you didn't report which version of DJGPP, or CWSDPMI, and > whether or not your code is operating in a Windows 98/SE/ME/XP etc > console. When operating in a Windows console, CWSDPMI is not being > used. The Windows DPMI host is being used. I'm testing on a Pentium 3 machine running FreeDOS, with cwsdpmi r7 and hdpmi32 v3.17. I'm cross-compiling from mingw64 with gcc 9.1, using the precompiled libraries from djcrx205.zip.