Malloc headache -- how to debug?

Discussion in 'Mac Programming' started by mpemburn, Jul 15, 2009.

  1. mpemburn macrumors member

    Jan 11, 2008
    Bel Air, MD USA
    Hi Folks,

    In the scanning app I'm working on, I'm getting the following error when I send the signal to cancel the scan operation:

    MyScan(25156,0xa046b720) malloc: *** free() called with 0x1add80 with refcount 0
    MyScan(25156,0xa046b720) malloc: *** auto malloc[25156]: agc error for object 0x1add80: Deallocating a non-block

    I'm not calling malloc() or free() anywhere so I'm guessing this must be happening in one of the dylibs I link to. How can I discover which one?

    Some background:
    The app uses the SANE API for image acquisition, which is written in C so I have to mix in C calls and data types to get it to work. My "Scan" object runs in a separate thread using NSOperation and the "sane_cancel()" command is called from the main thread. The command is trapped like this:

    while (status == SANE_STATUS_GOOD) {
    	status = sane_read (saneHandle,lineBuffer,maxlength,&bytesReturned);
    	//*** Exit loop if a sane_canel() order is issued
    	if (status == SANE_STATUS_CANCELLED) {
    	[dataBuffer appendBytes: lineBuffer length: bytesReturned];
    Thanks in advance,

    -- Mark
  2. Sander macrumors 6502

    Apr 24, 2008
    We'll probably need some more context here. You could do some "old-fashined printf-logging" in the code _after_ the while loop you're showing, to find out where exactly things are going wrong. It doesn't seem to be that the sane_cancel() call invalidates handles or anything, but I must admit I only quickly browsed through the SANE documentation. It does mention that the SANE API does not require any other operations to be re-entrant, so a frontend must not call any other operation until the cancelled operation has returned. Perhaps in addition to calling sane_cancel() from the main thread you're also doing something else?

Share This Page