I'm using this function to extract a substring, it works but there are two leaks:
-(NSString*)EstraiP:(NSString*)str ini:(NSString*)ini fin:(NSString*)fin occ:(int)occ{
NSRange rstr1;
for(int i=0; i < occ; i++){
rstr1=[str rangeOfString:fin];
str=[str substringFromIndex:rstr1.location+rstr1.length];
}
NSString* FinalStr;
rstr1=[str rangeOfString:ini];
if(occ==0){
if(rstr1.length==0)
return @"Non Trovato inizio";
FinalStr=[str substringFromIndex:(rstr1.location + rstr1.length)] ;
}else{
if(rstr1.length==0)
return @"Non Trovato inizio";
FinalStr=[str substringFromIndex:rstr1.location+rstr1.length] ;
}
NSRange rstr2=[FinalStr rangeOfString:fin];
if(rstr2.length==0)
return @"Non Trovata fine";
FinalStr=[FinalStr substringToIndex:rstr2.location];
return FinalStr;
}
This to lines leak some memory:
str=[str substringFromIndex:rstr1.location+rstr1.length];
FinalStr=[FinalStr substringToIndex:rstr2.location];
i looked around but did find nothing.... There is no alloc or retain so i shouldn' be releasing them...what can be the problem? i hope i explained myself
Thanks!