diff options
author | Lennart Poettering <lennart@poettering.net> | 2007-01-06 16:51:42 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2007-01-06 16:51:42 +0000 |
commit | 5b7e4f49787da905b9ec7d01eaf76462ca3a6e28 (patch) | |
tree | 4abd8004824ad0471aa7667823513536099aa3a0 /avahi-compat-libdns_sd | |
parent | b303e69589394fe25ff8f5fe6a17dfa6a4b07ea6 (diff) |
* handle NULL sdrefs gracefully.
* fix mutex locking order in DNSProcessResult
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1374 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
Diffstat (limited to 'avahi-compat-libdns_sd')
-rw-r--r-- | avahi-compat-libdns_sd/compat.c | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/avahi-compat-libdns_sd/compat.c b/avahi-compat-libdns_sd/compat.c index 9dc2281..9d8ff1c 100644 --- a/avahi-compat-libdns_sd/compat.c +++ b/avahi-compat-libdns_sd/compat.c @@ -469,25 +469,26 @@ static void sdref_unref(DNSServiceRef sdref) { } int DNSSD_API DNSServiceRefSockFD(DNSServiceRef sdref) { - if (!sdref || sdref->n_ref <= 0) - return -1; AVAHI_WARN_LINKAGE; + if (!sdref || sdref->n_ref <= 0) + return -1; + return sdref->main_fd; } DNSServiceErrorType DNSSD_API DNSServiceProcessResult(DNSServiceRef sdref) { DNSServiceErrorType ret = kDNSServiceErr_Unknown; - assert(sdref); - assert(sdref->n_ref >= 1); - AVAHI_WARN_LINKAGE; - ASSERT_SUCCESS(pthread_mutex_lock(&sdref->mutex)); - + if (!sdref || sdref->n_ref <= 0) + return kDNSServiceErr_BadParam; + sdref_ref(sdref); + + ASSERT_SUCCESS(pthread_mutex_lock(&sdref->mutex)); /* Cleanup notification socket */ if (read_command(sdref->main_fd) != COMMAND_POLL_DONE) @@ -512,10 +513,10 @@ DNSServiceErrorType DNSSD_API DNSServiceProcessResult(DNSServiceRef sdref) { finish: - sdref_unref(sdref); - ASSERT_SUCCESS(pthread_mutex_unlock(&sdref->mutex)); + sdref_unref(sdref); + return ret; } @@ -613,7 +614,6 @@ DNSServiceErrorType DNSSD_API DNSServiceBrowse( if (!ret_sdref) return kDNSServiceErr_BadParam; - *ret_sdref = NULL; assert(regtype); @@ -739,7 +739,10 @@ DNSServiceErrorType DNSSD_API DNSServiceResolve( AVAHI_WARN_LINKAGE; - assert(ret_sdref); + if (!ret_sdref) + return kDNSServiceErr_BadParam; + *ret_sdref = NULL; + assert(name); assert(regtype); assert(domain); @@ -853,7 +856,10 @@ DNSServiceErrorType DNSSD_API DNSServiceEnumerateDomains( AVAHI_WARN_LINKAGE; - assert(ret_sdref); + if (!ret_sdref) + return kDNSServiceErr_BadParam; + *ret_sdref = NULL; + assert(callback); if (interface == kDNSServiceInterfaceIndexLocalOnly || @@ -1096,7 +1102,6 @@ DNSServiceErrorType DNSSD_API DNSServiceRegister ( if (!ret_sdref) return kDNSServiceErr_BadParam; - *ret_sdref = NULL; if (!regtype) @@ -1210,10 +1215,12 @@ DNSServiceErrorType DNSSD_API DNSServiceUpdateRecord( int ret = kDNSServiceErr_Unknown; AvahiStringList *txt = NULL; - assert(sdref); AVAHI_WARN_LINKAGE; + if (!sdref || sdref->n_ref <= 0) + return kDNSServiceErr_BadParam; + if (flags || rref) { AVAHI_WARN_UNSUPPORTED; return kDNSServiceErr_Unsupported; |