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

  • SEARCH
  • Home
  • 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 7160173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:21:20+00:00 2026-05-28T13:21:20+00:00

I am in the process of converting the available SKP_SMTP library to implement an

  • 0

I am in the process of converting the available SKP_SMTP library to implement an SMTP client in my iPhone app. After a long and troubled work of bug fixing and memory checks, I have narrowed down the problems to only one. It happens that a memory leaks occurs in the call to CFStreamCreatePairWithSocketToCFHost (evidentiated by the Leaks tool in Instruments), which seems strange to me as the CFReadStreamRef parameters readStream and writeStream are either CFReleased at a later stage, or assigned to a correspondent NSStream object via __bridge_transfer (and that should eventually bring the streams memory management from CoreFoundation to ARC).
I’ve googled around but the only solutions I have found are under garbage collection(clearly not available in ARC): am I missing something or that should not happen?
Code following,
thanks a lot

@implementation NSStream (SKPSMTPExtensions)

+ (void)getStreamsToHostNamed:(NSString *)hostName port:(NSInteger)port inputStream:  (NSInputStream **)inputStream outputStream:(NSOutputStream **)outputStream
{
    CFHostRef           host;
    CFReadStreamRef     readStream;
    CFWriteStreamRef    writeStream;

    readStream = NULL;
    writeStream = NULL;

    host = CFHostCreateWithName(NULL, (__bridge_retained CFStringRef) hostName);
    if (host != NULL) 
    {
        // Memory leak at this line: strange as readStream & writeStream are either   CFReleased or _bridge_transfered to ARC 
        (void) CFStreamCreatePairWithSocketToCFHost(NULL, host, port, &readStream,   &writeStream);
        CFRelease(host);
    }

    if (inputStream == NULL) 
    {
        CFRelease(readStream);
    } 
    else 
    {
        *inputStream = (__bridge_transfer NSInputStream *) readStream;
    }
    if (outputStream == NULL) 
    {
        CFRelease(writeStream);
    } 
    else 
    {
        *outputStream = (__bridge_transfer NSOutputStream *) writeStream;
    }

}

@end
  • 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-28T13:21:21+00:00Added an answer on May 28, 2026 at 1:21 pm

    I think this statement leaks hostName:

    host = CFHostCreateWithName(NULL, (__bridge_retained CFStringRef) hostName);
    

    You should use a __bridge cast, not a __bridge_retained cast.

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

Sidebar

Related Questions

We're in the process of converting web app to IE8 (now client is using
I am in process of converting Visual Basic app into Python Django. Currently, it
I have downloaded an Android app (which is also available for iPhone and ipad).
I'm in the process of converting an app to use i18n/l10n on all its
I am in the process of converting a ASP.Net Web App to a C#
I am in the process of converting a excel work book into a web
What is the process of converting win32 application (a small popup window actually) to
Im in the process of converting my rails code which developed in version 2
I'm in the process of converting some LaTeX documentation to restructured text and having
I am in the process of converting an Access database to SQL Server 2005.

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.