• 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
malloc during selectAll -> crash
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

malloc during selectAll -> crash


  • Subject: malloc during selectAll -> crash
  • From: Lorenzo <email@hidden>
  • Date: Thu, 11 May 2006 16:16:08 +0200

I have verified that calling
    unsigned int  *buf = malloc(totItems);
during a [outlineView selectAll:sender], I get a crash, soon, or later on,
when I select any different window. The problem has gone away replacing the
malloc call with
    unsigned int  buf[totItems];
But since in some class variable case I "must" use malloc, and I get a crash
too, may you please help me to understand how to avoid this problem at
calling malloc?


The crash:
I have an outlineView. When I call selectAll automatically Cocoa invokes
outlineViewSelectionDidChange and, in this method I collect the items
currently selected into an NSMutableArray. As I have seen in some sample
code, I get the selected items this way.

//////////////////////
    NSMutableArray  *items = [NSMutableArray array];
    NSIndexSet      *selectedRows = [self selectedRowIndexes];
    unsigned int  i, totItems = [selectedRows count];
    if(totItems  == 0) return items ;

    unsigned int  *buf = malloc(totItems);

    NSRange  range = NSMakeRange([selectedRows firstIndex],
                             [selectedRows lastIndex] + 1);

    [selectedRows getIndexes:buf maxCount:totItems inIndexRange:&range];
    for(i = 0; i < totItems; i++){
        id    item = [self itemAtRow:buf[i]];
        if(item) [items addObject:item];
    }

    if(buf){
      free(buf);
      buf = nil;
    }
    return items ;

//////////////////////



Best Regards
--
Lorenzo
email: email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: malloc during selectAll -> crash
      • From: Ryan Britton <email@hidden>
    • Re: malloc during selectAll -> crash
      • From: Nick Zitzmann <email@hidden>
  • Prev by Date: NSTreeController Grouping Nodes - Grouping At All
  • Next by Date: Re: malloc during selectAll -> crash
  • Previous by thread: Re: NSTreeController Grouping Nodes - Grouping At All
  • Next by thread: Re: malloc during selectAll -> crash
  • Index(es):
    • Date
    • Thread