Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memory leak warning on return

im working on a old code and i have this warning message: Passed-by-value struct argument contains uninitialized data (e.g., via the field chain: 'origin.x'). If i could get dome help i would be very thankful :)

The code im using:

- (void)positionScroller
{
    CGRect screenFrame = [[UIScreen mainScreen] bounds];
    CGRect scrollerRect;

    if( self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown )
    {
        scrollerRect = CGRectMake( 0, 0, screenFrame.size.width, screenFrame.size.height );
    }
    else if( self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation == UIInterfaceOrientationLandscapeRight )
    {
        scrollerRect = CGRectMake( 0, 0, screenFrame.size.height, screenFrame.size.width );
    }

    _scroller.frame = scrollerRect;   <---This is where the compiler gives the warning
}

Best Regards.

like image 247
Bruno Avatar asked Dec 12 '22 05:12

Bruno


1 Answers

The thing is that the compiler can't be sure that one of the if/else-if blocks is ever reached, in which case, scrollerRect would still be uninitialized. You should either add a pure else statement or initialize scrollerRect, e.g. by setting it to CGRectZero.

By the way, this has nothing to do with a memory leak, it's more of a logic error.

like image 105
omz Avatar answered Dec 15 '22 00:12

omz