site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Received:X-YMail-OSG:X-Yahoo-Newman-Property:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Content-Transfer-Encoding; b=1zFuHuTtmZYln/KtMiEdpy13Y7h8XkiUARdODVm8Nycp6vqc+lbEtKrMv1nQOM+bi9XS5eHg7TwXl+Aqoi5kzyN5uI2uGrroBTJa9JjW9xdhjxvOVGyx7mGf9nUEDxchVgECwNlekpItgEf5ySwNgSwX9YMtC6xAhiihlsT6VL0= ; User-agent: Thunderbird 2.0.0.17 (Windows/20080914) Hello, all. I think I found a bug of the valloc(). I have lines of code which works like this. Are there any people who also notice this problem? Thank you. _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... 1. A hosting program calls my module when the user initiates "export" from the menu item of the hosting program. 2. The hosting program calls my module. Let's call the called function of the module as function "A". 3. For each slice of the files being exported, the hosting program calls the function "A" 4. My function "A" calls another function "B" to process things, while the "A" itself contains an "Init" function for set up things when it is first call for the file being exported, and "cleanup" functions for the last call for the file. 5. When the call is for the 1st one for the file, it allocates a fresh new memory space, and put the data into the memory space. 6. For every 4 calls, it saves the content of the memory space. This reduces time to save the export procedure. 7. for 2nd, 3rd calls, it "realloc" the memory to increase the memory space to make enough room for the new incoming data. 8. After saing the data, it frees the memory space. 9. Now, if the function is called again because there are still left data to process, it allocates a new memory space. 10. Now take the same procedure described above until the end of the file. When it allocates new memory space, it calls "valloc". One problem I saw happens when it frees old memory space after saving it and make a new memory space and start putting data into the space. When it puts data into the space, it sometimes crash while displaying error message which means, "the code tried modifing memory space which is freed." But I checked the call path and I confirmed that it allocates new memory space using valloc and it accesses the memory space. So, when I put some NSLog() function between the memory allocation and putting data into the space, it did not show the crash problem anymore. So, I replaced the valloc() with malloc() to see if the problem still exists. ( I removed the extra NSLog() function for beign sure. ) Then, it didn't show any crash problem. So, what I guess is.. while compilation the gcc may reorder the instruction and it makes "memcpy" call appear before the "valloc()" related call. ( memcpy() is used to put the data into the memory space. ) I use the Mac OS X 10.5.5 and Xcode 3.1.1. The gcc is the latest one which is installed with the Xcode tools. This email sent to site_archiver@lists.apple.com