[Q] valloc bug?
[Q] valloc bug?
- Subject: [Q] valloc bug?
- From: JongAm Park <email@hidden>
- Date: Wed, 01 Oct 2008 10:35:42 -0700
Hello, all. I think I found a bug of the valloc().
I have lines of code which works like this.
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.
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 (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden