summaryrefslogtreecommitdiff
path: root/src/htsback.c
diff options
context:
space:
mode:
authorXavier Roche <xroche@users.noreply.github.com>2013-09-06 17:32:04 +0000
committerXavier Roche <xroche@users.noreply.github.com>2013-09-06 17:32:04 +0000
commitbd28ac98ded17e44c66d4b8b7e6a739b45dc8ae0 (patch)
tree8590864529e01070f084a7aa09a19639fd181ab8 /src/htsback.c
parentfa1e5e31132be81e2605706a43a59227a4041f42 (diff)
Fixed dangling pointer which probably explain the crash at libhttrack.so:0x639d0
Diffstat (limited to 'src/htsback.c')
-rw-r--r--src/htsback.c69
1 files changed, 31 insertions, 38 deletions
diff --git a/src/htsback.c b/src/htsback.c
index ccfdba1..dfb522f 100644
--- a/src/htsback.c
+++ b/src/htsback.c
@@ -2147,10 +2147,10 @@ typedef struct {
} HostlookupStruct;
void Hostlookup(void *pP) {
HostlookupStruct *str = (HostlookupStruct *) pP;
+ httrackp *const opt = str->opt;
char iadr[256];
- t_dnscache *cache = _hts_cache(str->opt); // adresse du cache
t_hostent *hp;
- int error_found = 0;
+ t_fullhostent fullhostent_buffer;
// recopier (après id:pass)
#if DEBUGDNS
@@ -2164,49 +2164,49 @@ void Hostlookup(void *pP) {
if ((a = jump_toport(iadr)))
*a = '\0'; // get rid of it
}
- freet(pP);
- hts_mutexlock(&dns_lock);
+ // resolve
+ hp = vxgethostbyname(iadr, &fullhostent_buffer);
+
+ // found
+ if (hp != NULL) {
+ t_dnscache *cache;
+ int error_found = 0;
+
+ hts_mutexlock(&opt->state.lock);
- while(cache->n) {
+ for(cache = _hts_cache(opt); cache->n != NULL; cache = cache->n) {
+ if (strcmp(cache->iadr, iadr) == 0) {
+ error_found = 1;
+ }
+ }
if (strcmp(cache->iadr, iadr) == 0) {
error_found = 1;
}
- cache = cache->n; // calculer queue
- }
- if (strcmp(cache->iadr, iadr) == 0) {
- error_found = 1;
- }
- if (!error_found) {
- // en gros copie de hts_gethostbyname sans le return
- cache->n = (t_dnscache *) calloct(1, sizeof(t_dnscache));
- if (cache->n != NULL) {
- t_fullhostent fullhostent_buffer;
+ if (!error_found) {
+ // en gros copie de hts_gethostbyname sans le return
+ cache->n = (t_dnscache *) calloct(1, sizeof(t_dnscache));
+ if (cache->n != NULL) {
+ strcpybuff(cache->n->iadr, iadr);
+ cache->n->host_length = 0; /* pour le moment rien */
+ cache->n->n = NULL;
- strcpybuff(cache->n->iadr, iadr);
- cache->n->host_length = 0; /* pour le moment rien */
- cache->n->n = NULL;
-
- /* resolve */
-#if DEBUGDNS
- printf("gethostbyname() in progress for %s\n", iadr);
-#endif
- cache->n->host_length = -1;
- memset(cache->n->host_addr, 0, sizeof(cache->n->host_addr));
- hp = vxgethostbyname(iadr, &fullhostent_buffer);
- if (hp != NULL) {
+ cache->n->host_length = -1;
+ memset(cache->n->host_addr, 0, sizeof(cache->n->host_addr));
memcpy(cache->n->host_addr, hp->h_addr, hp->h_length);
cache->n->host_length = hp->h_length;
}
- }
- } else {
+ } else {
#if DEBUGDNS
- printf("aborting resolv for %s (found)\n", iadr);
+ printf("aborting resolv for %s (found)\n", iadr);
#endif
+ }
+
+ hts_mutexrelease(&opt->state.lock);
}
- hts_mutexrelease(&dns_lock);
+ freet(pP);
#if DEBUGDNS
printf("quitting resolv for %s (result: %d)\n", iadr,
@@ -2250,9 +2250,6 @@ void back_solve(httrackp * opt, lien_back * back) {
hts_newthread(Hostlookup, str);
}
}
-#else
- /*t_hostent* h= */
- /*hts_gethostbyname(a); */// calcul
#endif
#else
#if USE_BEGINTHREAD
@@ -2262,10 +2259,6 @@ void back_solve(httrackp * opt, lien_back * back) {
strcpybuff(p, a);
hts_newthread(Hostlookup, p);
}
-#else
- // Sous Unix, le gethostbyname() est bloquant..
- /*t_hostent* h= */
- /*hts_gethostbyname(a); */// calcul
#endif
#endif
}