Commit 07de3c9d authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

T. Bharath's patch that sets up a few necessary buffers in the duphandle()

function
parent 8950a2df
Loading
Loading
Loading
Loading
+39 −7
Original line number Diff line number Diff line
@@ -255,7 +255,8 @@ CURL *curl_easy_duphandle(CURL *incurl)
{
  struct SessionHandle *data=(struct SessionHandle *)incurl;

  struct SessionHandle *outcurl = malloc(sizeof(struct SessionHandle));
  struct SessionHandle *outcurl = (struct SessionHandle *)
    malloc(sizeof(struct SessionHandle));

  if(NULL == outcurl)
    return NULL; /* failure */
@@ -263,17 +264,48 @@ CURL *curl_easy_duphandle(CURL *incurl)
  /* start with clearing the entire new struct */
  memset(outcurl, 0, sizeof(struct SessionHandle));

  /*
   * We setup a few buffers we need. We should probably make them
   * get setup on-demand in the code, as that would probably decrease
   * the likeliness of us forgetting to init a buffer here in the future.
   */
  outcurl->state.headerbuff=(char*)malloc(HEADERSIZE);
  if(!outcurl->state.headerbuff) {
    free(outcurl); /* free the memory again */
    return NULL;
  }
  outcurl->state.headersize=HEADERSIZE;

  /* copy all userdefined values */
  outcurl->set = data->set;
  outcurl->state.numconnects = data->state.numconnects;
  outcurl->state.connects = (struct connectdata **)
      malloc(sizeof(struct connectdata *) * outcurl->state.numconnects);

  if(!outcurl->state.connects) {
    free(outcurl->state.headerbuff);
    free(outcurl);
    return NULL;
  }
  memset(outcurl->state.connects, 0,
         sizeof(struct connectdata *)*outcurl->state.numconnects);

  outcurl->progress.flags    = data->progress.flags;
  outcurl->progress.callback = data->progress.callback;

  /* duplicate all values in 'change' */
  if(data->change.url) {
    outcurl->change.url = strdup(data->change.url);
    outcurl->change.url_alloc = TRUE;
  }
  if(data->change.proxy) {
    outcurl->change.proxy = strdup(data->change.proxy);
    outcurl->change.proxy_alloc = TRUE;
  }
  if(data->change.referer) {
    outcurl->change.referer = strdup(data->change.referer);
  /* set all the alloc-bits */
  outcurl->change.url_alloc =
    outcurl->change.proxy_alloc =
    outcurl->change.referer_alloc = TRUE;
  }

  return outcurl;
}