I may be off on an island by myself here but I thought I'd add some more info just in case someone recognizes it and has a useful thought.
The error described below occurs because the data I sent through NSFileHandle to NSData (in the subtask) was actually the elements of a vector<myStruct> [just the array, not the vector header]. myStruct itself contains four fields which are STL containers and, hence, have ctors/dtors, etc., of their own. The fields are two strings, a list and a map, the latter two being empty. If I create a pseudo_myStruct for testing that lacks these four fields, then everything works. Therefore, there is some STL/malloc issue involved in recreating vector<myStruct> with its STL containers from the bytes recovered from an NSData object regardless of how one accesses those bytes. [I've tried all of the available NSData methods.] Also, I had expected the copy in the subtask to be shallow but I might have been mistaken on that score. That is the limit of my knowledge about this and, if anyone has been down this road before, I'd appreciate a clue or two. Thanks again. >In a Cocoa app targeting Leopard, I am getting a malloc error when using the >NSData method > >- (void)getBytes:(void *)buffer > > >My function is as follows: > >-(void)getDataSz:(void*)data ofSize:(NSUInteger)sz >{ > NSData *theData = [input readDataOfLength:sz]; > [theData getBytes:data]; // <-- no error when commented out >} > >This function is actually in a subtask and >input >is an NSFileHandle. > >Input is reading data (from the main task) correctly with no error. >However, > >[theData getBytes:data]; > >generates the following error (most of the time): > >malloc: *** free() called with 0x9aadca0 with refcount 0 >malloc: *** auto malloc[3230]: agc error for object 0x9aadca0: Deallocating >a non-block > >In normal operation, getDataSz takes in a buffer allocated by an STL vector >in the following call: > >[mySubtaskServer getDataSz:&my_vec[0] ofSize:dataSize]; > >If (just for testing), I replace the argument, data, with a local malloc >buffer (in getDataSz) and free it before exiting, then I do not see this >error. > >FWIW, I also do not see this error in an earlier call in which the amount of >data read is less than a block (4096 bytes). > >The Build options have >Call C++ Default Ctors/Dtors in Objective-C >set to YES >and garbage-collection is Supported. > >Compiler is gcc 4.2. > >Is there something else I should be doing here? >Thanks. -- Mike McLaughlin _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com