Releasing ONHost?

  • I'm having trouble releasing ONHost.  When I run ObjAlloc on my app I see=20
    ONHost  not releasing when there is an exception that is rescued (due to=20
    hostname not resolving for example).  If I do a [host release]; I get a=20
    segfault,..  I am just using:

    ONHost* host;
    [host hostForHostname:server];

    It looks like hostForHostname implies alloc?

    Thanks in advance,
    Jason DiCioccio
  •   Feel free to take a look at the source for ONHost.  A couple things to
    point out -- ONHost caches results, so unless you call +flushCache, the
    ONHost will stick around.  This is important since host lookups are
    expensive.  Also, ONHost caches lookup failures since DNS timeouts are
    VERY expensive.

    -tim

    On Tuesday, February 26, 2002, at 08:50  AM, Jason DiCioccio wrote:

    > I'm having trouble releasing ONHost.  When I run ObjAlloc on my app I
    > see ONHost  not releasing when there is an exception that is rescued
    > (due to hostname not resolving for example).  If I do a [host release];
    > I get a segfault,..  I am just using:
    >
    > ONHost* host;
    > [host hostForHostname:server];
    >
    > It looks like hostForHostname implies alloc?
    >
    > Thanks in advance,
    > Jason DiCioccio
    >
  • Hmm.. Even if I call +flushCache the object still seems to stay (I tried=20
    calling it from the exception handler)..  I tried this yesterday but forgot =

    to mention it in the email :(.. If I call flushHostCache I get another=20
    segfault .. I'm just trying to deallocate the object when I'm done doing=20
    host resolution ;-)

    I must be missing something :)

    Cheers,
    -JD-

    --On Tuesday, February 26, 2002 9:39 AM -0800 "Timothy J. Wood"=20
    <tjw...> wrote:

    >
    >
    > Feel free to take a look at the source for ONHost.  A couple things to
    > point out -- ONHost caches results, so unless you call +flushCache, the
    > ONHost will stick around.  This is important since host lookups are
    > expensive.  Also, ONHost caches lookup failures since DNS timeouts are
    > VERY expensive.
    >
    > -tim
    >
    >
    >
    > On Tuesday, February 26, 2002, at 08:50  AM, Jason DiCioccio wrote:
    >
    >> I'm having trouble releasing ONHost.  When I run ObjAlloc on my app I
    >> see ONHost  not releasing when there is an exception that is rescued
    >> (due to hostname not resolving for example).  If I do a [host release];
    >> I get a segfault,..  I am just using:
    >>
    >> ONHost* host;
    >> [host hostForHostname:server];
    >>
    >> It looks like hostForHostname implies alloc?
    >>
    >> Thanks in advance,
    >> Jason DiCioccio
    >>
    >
    > _______________________________________________
    > MacOSX-dev mailing list
    > <MacOSX-dev...>
    > http://www.omnigroup.com/mailman/listinfo/macosx-dev
  •   Well, it's entirely possible that there is a bug in ONHost.  Ken --
    can you offer any advice?

    -tim

    On Tuesday, February 26, 2002, at 10:37  AM, Jason DiCioccio wrote:

    > Hmm.. Even if I call +flushCache the object still seems to stay (I
    > tried calling it from the exception handler)..  I tried this yesterday
    > but forgot to mention it in the email :(.. If I call flushHostCache I
    > get another segfault .. I'm just trying to deallocate the object when
    > I'm done doing host resolution ;-)
    >
    > I must be missing something :)
    >
    > Cheers,
    > -JD-
    >
    > --On Tuesday, February 26, 2002 9:39 AM -0800 "Timothy J. Wood"
    > <tjw...> wrote:
    >
    >>
    >>
    >> Feel free to take a look at the source for ONHost.  A couple things
    >> to
    >> point out -- ONHost caches results, so unless you call +flushCache, the
    >> ONHost will stick around.  This is important since host lookups are
    >> expensive.  Also, ONHost caches lookup failures since DNS timeouts are
    >> VERY expensive.
    >>
    >> -tim
    >>
    >>
    >>
    >> On Tuesday, February 26, 2002, at 08:50  AM, Jason DiCioccio wrote:
    >>
    >>> I'm having trouble releasing ONHost.  When I run ObjAlloc on my app I
    >>> see ONHost  not releasing when there is an exception that is rescued
    >>> (due to hostname not resolving for example).  If I do a [host
    >>> release];
    >>> I get a segfault,..  I am just using:
    >>>
    >>> ONHost* host;
    >>> [host hostForHostname:server];
    >>>
    >>> It looks like hostForHostname implies alloc?
    >>>
    >>> Thanks in advance,
    >>> Jason DiCioccio
    >>>
    >>
    >> _______________________________________________
    >> MacOSX-dev mailing list
    >> <MacOSX-dev...>
    >> http://www.omnigroup.com/mailman/listinfo/macosx-dev
    >
    >
  • (I forgot to carbon-copy the list on the resolution of this problem.
    The bug fix will be included in the next source release of
    OmniNetworking.)

    Thanks for reporting the bug!  Here's a fixed implementation of
    -_initWithHostname: (which is where the leak was happening).

        Ken

    - _initWithHostname:(NSString *)aHostname;
    {
        if ([super init] == nil)
    return nil;

        hostname = [aHostname retain];
        addresses = [[NSMutableArray alloc] init];

        if ([self _tryLocalhost] || [self _tryToLookupHostInfoAsDottedQuad])
            return self;

        NS_DURING {
    #if defined(ONHOST_USE_THREADSAFE_RESOLVER)
            [self _lookupHostInfoUsingThreadSafeResolver];
    #elif defined(ONHOST_USE_THREADSAFE_LOOKUPD_GETHOSTBYNAME)
            [self _lookupHostInfoByLookupDaemon];
    #else
            [self _lookupHostInfoByPipe];
    #endif
        } NS_HANDLER {
            [self release];
            [localException raise];
        } NS_ENDHANDLER;
        if (expirationDate == nil)
            expirationDate = [[NSDate alloc]
    initWithTimeIntervalSinceNow:ONHostDefaultTimeToLiveTimeInterval];

        return self;
    }
previous month february 2002 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28      
Go to today