Commit e64dacb4 authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

better checking that strdup() works

parent fff01f24
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -127,10 +127,18 @@ mk_hash_element(char *key, size_t key_len, const void *p)
    (curl_hash_element *) malloc(sizeof(curl_hash_element));

  if(he) {
    he->key = strdup(key);
    char *dup = strdup(key);
    if(dup) {
      he->key = dup;
      he->key_len = key_len;
      he->ptr = (void *) p;
    }
    else {
      /* failed to duplicate the key, free memory and fail */
      free(he);
      he = NULL;
    }
  }
  return he;
}