Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / August 2007



Tip: Looking for answers? Try searching our database.

[NSFileHandle closeFile] crashes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alexander Clauss - 23 Aug 2007 14:50 GMT
I've encountered a problem with the "closeFile" message of
"NSFileHandle". Whenever I try to close a file using the "closeFile"
message in one of my applications it will crash. I can narrow the
problem down to the following routine (which means, there's nothing else
that is done but creating the file handle and closing the file again. My
original programm also loaded some parts of the file with the same crash
as a result):

- (void)doSomething:(NSString*)path
{
   NSFileHandle *handle =
       [NSFileHandle fileHandleForReadingAtPath: path];
   [handle closeFile];
}

The crash occurs as soon as the routine "doSomething" is left and the
programm counter returns to the caller.

When I put these two lines of code directly into  "main()" it does not
crash at all. So I created a simple XCOde project to demonstrate the
problem (in case someone is interested in testing this as well):

 <http://www.clauss-net.de/crashtest.zip>

Run the program in the debugger. A window will open with a button, click
the button and you should end in the Debugger, the programm stopped at a
breakpoint. Now use the "Step Over" button in the debugger to go on step
by step. As soon as you reach the end of the routine and return to the
caller method, the crash occurs. It looks like the stack gets corrupt.
If you remove the "closeFile" call, everything works fine.

This small example will work without a crash when there's no breakpoint
set or if not running in the Debugger. But this is not the case in more
complex applications where the stack usage is much larger (like my
application where I've encountered this problem). It looks like the
"closeFile" call messes up the Stack: This may explain, why there's no
problem at all when the code from above is inserted directly in "main()"
(the Stack is very tiny) and the problem occurs in the debugger with the
small test case and even without the debugger in a complex application:
The larger the stack when closeFile is used, the more likely it is that
the "closeFile" can mess up important data on the  stack (but this is
only a guess).

I've looked for any information about this problem in the web and in the
Usenet but haven't found anything with one exception:

<http://forums.macrumors.com/archive/index.php/t-136909.html>

This is an almost two year old posting in a forum where someone had
exactly the same problem. Also no solution for the problem in this forum
thread. Not calling "closeFile" at all would avoid the crash, but this
may not always an option if a file has to be released in time. Not using
closeFile would close and release the file when the next autorelease
takes place. While this might work in most cases, it is not always an
option.

I'm relatively new in Cocoa programming, so I wonder if this is really a
bug of the MacOS or am I doing something wrong? Or is it just the
documentation from Apple which is not telling everything we have to know
about this. It'hard to believe that I'm the only one with this problem.
If this is really a bug, I'll send a bugreport to Apple (though because
this problem seems to exist at least for two years, I would have
expected that Apple would have been notified about this already).

Signature

Alexander

matt neuburg - 23 Aug 2007 15:59 GMT
> I've encountered a problem with the "closeFile" message of
> "NSFileHandle". Whenever I try to close a file using the "closeFile"
[quoted text clipped - 59 lines]
> this problem seems to exist at least for two years, I would have
> expected that Apple would have been notified about this already).

Choose Debug > Variables View > Enable Data Formatters so that it is
**unchecked**. The problem will go away. m.

Signature

matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/
Tiger - http://www.takecontrolbooks.com/tiger-customizing.html
AppleScript - http://www.amazon.com/gp/product/0596102119
Read TidBITS! It's free and smart. http://www.tidbits.com

Florian Zschocke - 23 Aug 2007 19:28 GMT
matt@tidbits.com (matt neuburg) schrieb:


>> I'm relatively new in Cocoa programming, so I wonder if this is really a
>> bug of the MacOS or am I doing something wrong? Or is it just the
[quoted text clipped - 6 lines]
> Choose Debug > Variables View > Enable Data Formatters so that it is
> **unchecked**. The problem will go away. m.

Hm, can you please explain me the technical background of this behavior.

Thanks a lot - Florian
Alexander Clauss - 23 Aug 2007 23:28 GMT
> Choose Debug > Variables View > Enable Data Formatters so that it is
> **unchecked**. The problem will go away. m.

Thanks. Do you know why this will fix the problem?

Signature

Alexander

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.