Commit 2cff2518 authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

Curl_resolv() now returns a different struct, and it contains a reference

counter so that the caller needs to decrease that counter when done with
the returned data.

If compiled with MALLOCDEBUG I've added some extra checking that the counter
is decreased before a handle is closed etc.
parent 73d996bf
Loading
Loading
Loading
Loading
+11 −6
Original line number Diff line number Diff line
@@ -206,7 +206,7 @@ static CURLcode bindlocal(struct connectdata *conn,
   *************************************************************/
  if (strlen(data->set.device)<255) {
    struct sockaddr_in sa;
    Curl_addrinfo *h=NULL;
    struct Curl_dns_entry *h=NULL;
    size_t size;
    char myhost[256] = "";
    in_addr_t in;
@@ -247,12 +247,17 @@ static CURLcode bindlocal(struct connectdata *conn,
    if (INADDR_NONE != in) {

      if ( h ) {
        Curl_addrinfo *addr = h->addr;

        h->inuse--; /* decrease the use-counter, we don't need it anymore
                       after this function has returned */

        memset((char *)&sa, 0, sizeof(sa));
#ifdef ENABLE_IPV6
        memcpy((char *)&sa.sin_addr, h->ai_addr, h->ai_addrlen);        
        sa.sin_family = h->ai_family;
        memcpy((char *)&sa.sin_addr, addr->ai_addr, addr->ai_addrlen);        
        sa.sin_family = addr->ai_family;
#else
        memcpy((char *)&sa.sin_addr, h->h_addr, h->h_length);
        memcpy((char *)&sa.sin_addr, addr->h_addr, addr->h_length);
        sa.sin_family = AF_INET;
#endif
        sa.sin_addr.s_addr = in;
@@ -410,7 +415,7 @@ CURLcode Curl_is_connected(struct connectdata *conn,
 */

CURLcode Curl_connecthost(struct connectdata *conn,  /* context */
                          Curl_addrinfo *remotehost, /* use one in here */
                          struct Curl_dns_entry *remotehost, /* use this one */
                          int port,                  /* connect to this */
                          int *sockconn,             /* the connected socket */
                          Curl_ipconnect **addr,     /* the one we used */
@@ -479,7 +484,7 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */
    struct addrinfo *ai;
    port =0; /* prevent compiler warning */

    for (ai = remotehost; ai; ai = ai->ai_next, aliasindex++) {
    for (ai = remotehost->addr; ai; ai = ai->ai_next, aliasindex++) {
      sockfd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
      if (sockfd < 0)
        continue;
+1 −1
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ CURLcode Curl_is_connected(struct connectdata *conn,
                           bool *connected);

CURLcode Curl_connecthost(struct connectdata *conn,
                          Curl_addrinfo *host, /* connect to this */
                          struct Curl_dns_entry *host, /* connect to this */
                          int port,       /* connect to this port number */
                          int *sockconn,  /* not set if error is returned */
                          Curl_ipconnect **addr, /* the one we used */
+6 −5
Original line number Diff line number Diff line
@@ -1184,7 +1184,6 @@ CURLcode ftp_use_port(struct connectdata *conn)
   */
  struct sockaddr_in sa;
  struct hostent *h=NULL;
  char *hostdataptr=NULL;
  unsigned short porttouse;
  char myhost[256] = "";
  bool sa_filled_in = FALSE;
@@ -1215,6 +1214,9 @@ CURLcode ftp_use_port(struct connectdata *conn)
    sa_filled_in = TRUE; /* the sa struct is filled in */
  }

  if(h)
    h->inuse--; /* when we return from here, we can forget about this */

  if ( h || sa_filled_in) {
    if( (portsock = socket(AF_INET, SOCK_STREAM, 0)) >= 0 ) {
      int size;
@@ -1250,19 +1252,16 @@ CURLcode ftp_use_port(struct connectdata *conn)
        
        if ( listen(portsock, 1) < 0 ) {
          failf(data, "listen(2) failed on socket");
          free(hostdataptr);
          return CURLE_FTP_PORT_FAILED;
        }
      }
      else {
        failf(data, "bind(2) failed on socket");
        free(hostdataptr);
        return CURLE_FTP_PORT_FAILED;
      }
    }
    else {
      failf(data, "socket(2) failed (%s)");
      free(hostdataptr);
      return CURLE_FTP_PORT_FAILED;
    }
  }
@@ -1332,7 +1331,7 @@ CURLcode ftp_use_pasv(struct connectdata *conn,
  char *buf = data->state.buffer; /* this is our buffer */
  int ftpcode; /* receive FTP response codes in this */
  CURLcode result;
  Curl_addrinfo *addr=NULL;
  struct Curl_dns_entry *addr=NULL;
  Curl_ipconnect *conninfo;

  /*
@@ -1480,6 +1479,8 @@ CURLcode ftp_use_pasv(struct connectdata *conn,
                            &conninfo,
                            connected);

  addr->inuse--; /* we're done using this address */

  /*
   * When this is used from the multi interface, this might've returned with
   * the 'connected' set to FALSE and thus we are now awaiting a non-blocking
+9 −9
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@

#include <string.h>
#include <stdlib.h>

#include "hash.h"
#include "llist.h"

@@ -128,7 +129,6 @@ _mk_hash_element (curl_hash_element **e, char *key, size_t key_len, const void *
  (*e)->key = strdup(key);
  (*e)->key_len = key_len;
  (*e)->ptr = (void *) p;

  return 0;
}
/* }}} */
@@ -195,10 +195,10 @@ Curl_hash_delete(curl_hash *h, char *key, size_t key_len)
}
/* }}} */

/* {{{ int curl_hash_find (curl_hash *, char *, size_t, void **)
/* {{{ int curl_hash_pick (curl_hash *, char *, size_t, void **)
 */
int 
Curl_hash_find(curl_hash *h, char *key, size_t key_len, void **p)
void *
Curl_hash_pick(curl_hash *h, char *key, size_t key_len)
{
  curl_llist_element *le;
  curl_hash_element  *he;
@@ -209,12 +209,11 @@ Curl_hash_find(curl_hash *h, char *key, size_t key_len, void **p)
       le = CURL_LLIST_NEXT(le)) {
    he = CURL_LLIST_VALP(le);
    if (_hash_key_compare(he->key, he->key_len, key, key_len)) {
      *p = he->ptr;
      return 1;
      return he->ptr;
    }
  }

  return 0;
  return NULL;
}
/* }}} */

@@ -222,7 +221,7 @@ Curl_hash_find(curl_hash *h, char *key, size_t key_len, void **p)
 */
void 
Curl_hash_apply(curl_hash *h, void *user,
                void (*cb)(void *, curl_hash_element *))
                void (*cb)(void *user, void *ptr))
{
  curl_llist_element  *le;
  int                  i;
@@ -231,7 +230,8 @@ Curl_hash_apply(curl_hash *h, void *user,
    for (le = CURL_LLIST_HEAD(h->table[i]);
         le != NULL;
         le = CURL_LLIST_NEXT(le)) {
      cb(user, (curl_hash_element *) CURL_LLIST_VALP(le));
      curl_hash_element *el = CURL_LLIST_VALP(le);
      cb(user, el->ptr);
    }
  }
}
+4 −5
Original line number Diff line number Diff line
@@ -49,15 +49,14 @@ void Curl_hash_init(curl_hash *, int, curl_hash_dtor);
curl_hash *Curl_hash_alloc(int, curl_hash_dtor);
int Curl_hash_add(curl_hash *, char *, size_t, const void *);
int Curl_hash_delete(curl_hash *h, char *key, size_t key_len);
int Curl_hash_find(curl_hash *, char *, size_t, void **p);
void Curl_hash_apply(curl_hash *h, void *user, void (*cb)(void *, curl_hash_element *));
void *Curl_hash_pick(curl_hash *, char *, size_t);
void Curl_hash_apply(curl_hash *h, void *user,
                     void (*cb)(void *user, void *ptr));
int Curl_hash_count(curl_hash *h);
void Curl_hash_clean(curl_hash *h);
void Curl_hash_clean_with_criterium(curl_hash *h, void *user, int (*comp)(void *, void *));
void Curl_hash_destroy(curl_hash *h);

#define Curl_hash_update Curl_hash_add

#endif

/*
Loading