Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1031649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T13:57:44+00:00 2026-05-16T13:57:44+00:00

I was wondering how people handle return statements in a function. I have a

  • 0

I was wondering how people handle return statements in a function. I have a method that allocates some memory but has a return false; statement when a function goes wrong. this statement is located about half way through the function so my memory is leaked if that function fails. This isn’t the only return …; statement I have in this function. What would stackoverflow recommend doing to clean up the code in a function with a few return statements in it?

if( true == OpenFtpConnection() )
{
    AfxMessageBox( _T( "Connection to internet and ftp server found" ) );

    // set the directory to where the xml file lives
    if( false == FtpSetCurrentDirectory( m_ftpHandle, _T(_FTP_XML_LOCATION) ) )
        return false;

    HINTERNET xmlHandle = NULL;
    WIN32_FIND_DATA fileData;
    SYSTEMTIME fileWriteTime;
    xmlHandle = FtpFindFirstFile( m_ftpHandle, _T("TPCFeed.xml"), &fileData, INTERNET_FLAG_RELOAD, 0 );
    if( NULL == xmlHandle )
        return false;
    else
    {
        // get the write time of the ftp file
        FileTimeToSystemTime( &fileData.ftLastWriteTime, &fileWriteTime );

        // get the write time of the local file
        HANDLE localFileHandle = NULL;
        localFileHandle = CreateFile( _T(_XML_FILENAME_PATH), FILE_READ_ATTRIBUTES,
                                 FILE_SHARE_READ, NULL, OPEN_EXISTING,
                                 NULL, NULL );
        if( INVALID_HANDLE_VALUE == localFileHandle )
        {
            AfxMessageBox( _T( "opening file failed, file not found" ) );
            return false;
        }
        else
        {
            CloseHandle( localFileHandle );
        }


        // close the FtpFindFirstFile() handle
        InternetCloseHandle( xmlHandle );
    }


    // download xml file to disk
    //if( false == FtpGetFile( m_ftpHandle, _T("TPCFeed.xml"), _T(_XML_FILENAME_PATH), FALSE, 
    //                       FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_BINARY, 0 ) )
    //  return false;

}
else
{
    AfxMessageBox( _T( "No Connection to internet or ftp server found" ) );
    return false;
}
if( true == CloseFtpConnection() )
    AfxMessageBox( _T( "Connection to internet closed" ) );
else
    AfxMessageBox( _T( "Connection to internet not closed" ) );
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T13:57:45+00:00Added an answer on May 16, 2026 at 1:57 pm

    Clarity is the most important thing. Many times, having multiple return points can make the program flow less obvious and thus more prone to bugs; but on the other hand, sometimes early returns are quite obvious; their meaning and purpose is clear. So I tend to avoid any hard rules about that.

    You might get more mileage if you actually post the code you want to clean up though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering how people handle a ListBox control that has no items? e.g.
I was wondering if people could post some examples of interesting websites and web
Just trying to canvas some opinions here. I was wondering how people go about
just wondering what tips people have for avoiding game synchronisation issues in multiplayer games
I was wondering how other people implemented this scenario. I have an internal rails
I have some web pages I want people to be logged in to see.
I was wondering - how do people handle importing large numbers of commonly used
Just wondering what people had for ideas on how best to handle events in
I was wondering how people handle dealing with references across multiple users across multiple
I am wondering how people handle nested/complex routes for an application when using a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.