function to get the file name of an URL
<p>I have some source code to get the file name of an url</p>

<p>for example:</p>

<p><a href="http://www.google.com/a.pdf" rel="nofollow">http://www.google.com/a.pdf</a></p>

<p>I hope to get a.pdf</p>

<p>because the way to join 2 NSStrings I can get is 'appendString' which only for adding a string at right side, so I planned to check each char one by one from the right side of string 'http://www.google.com/a.pdf', when it reach at the char '/', stop the checking, return string fdp.a , after that I change fdp.a to a.pdf</p>

<p>source codes are below</p>

<pre><code>-(NSMutableString *) getSubStringAfterH :  originalString:(NSString *)s0 
{
    NSInteger i,l;
    l=[s0 length];
    NSMutableString *h=[[NSMutableString alloc] init];

    NSMutableString *ttt=[[NSMutableString alloc] init  ];
     for(i=l-1;i&gt;=0;i--) //check each char one by one from the right side of string 'http://www.google.com/a.pdf', when it reach at the char '/', stop
    {
        ttt=[s0 substringWithRange:NSMakeRange(i, 1)];
         if([ttt isEqualToString:@"/"]) 
        { 
            break;
        }
            else
        {
             [h appendString:ttt];
        } 
     }
     [ttt release];
     NSMutableString *h1=[[[NSMutableString alloc] initWithFormat:@""] autorelease];

    for (i=[h length]-1;i&gt;=0;i--)
    {
            NSMutableString *t1=[[NSMutableString alloc] init ];
        t1=[h substringWithRange:NSMakeRange(i, 1)];
        [h1 appendString:t1];
            [t1 release];
    } 
    [h release];
    return h1;
}
</code></pre>

<p>h1 can reuturn the coorect string a.pdf, but if it returns to the codes where it was called, after a while system reports
'double free
<em>*</em> set a breakpoint in malloc_error_break to debug'</p>

<p>I checked a long time and foudn that if I removed the code      </p>

<p>ttt=[s0 substringWithRange:NSMakeRange(i, 1)];</p>

<p>everything will be Ok (of course getSubStringAfterH can not returns the corrent result I expected.), no error reported.</p>

<p>I try to fix the bug a few hours, but still no clue.</p>

<p>Welcome any comment</p>

<p>Thanks 
interdev  </p>
