• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Problem with NSData
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with NSData


  • Subject: Problem with NSData
  • From: "McLaughlin, Michael P." <email@hidden>
  • Date: Mon, 5 Apr 2010 11:12:32 -0400
  • Acceptlanguage: en-US
  • Thread-topic: Problem with NSData

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 (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Problem with NSData
      • From: Graham Cox <email@hidden>
  • Prev by Date: NSMutableURLRequest: How to change Request URI?
  • Next by Date: Re: Finding managed objects by URI representation
  • Previous by thread: Re: NSMutableURLRequest: How to change Request URI?
  • Next by thread: Re: Problem with NSData
  • Index(es):
    • Date
    • Thread