Commit 783b3c7b authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

http2: separate multiplex/pipelining + cleanup memory leaks

parent 02ec1ced
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -558,6 +558,9 @@ CURLPAUSE_RECV 7.18.0
CURLPAUSE_RECV_CONT             7.18.0
CURLPAUSE_SEND                  7.18.0
CURLPAUSE_SEND_CONT             7.18.0
CURLPIPE_HTTP1                  7.43.0
CURLPIPE_MULTIPLEX              7.43.0
CURLPIPE_NOTHING                7.43.0
CURLPROTO_ALL                   7.19.4
CURLPROTO_DICT                  7.19.4
CURLPROTO_FILE                  7.19.4
+33 −10
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@
 * Forward declarations.
 */

static CURLcode http_disconnect(struct connectdata *conn, bool dead);
static int http_getsock_do(struct connectdata *conn,
                           curl_socket_t *socks,
                           int numsocks);
@@ -116,7 +117,7 @@ const struct Curl_handler Curl_handler_http = {
  http_getsock_do,                      /* doing_getsock */
  ZERO_NULL,                            /* domore_getsock */
  ZERO_NULL,                            /* perform_getsock */
  ZERO_NULL,                            /* disconnect */
  http_disconnect,                      /* disconnect */
  ZERO_NULL,                            /* readwrite */
  PORT_HTTP,                            /* defport */
  CURLPROTO_HTTP,                       /* protocol */
@@ -140,7 +141,7 @@ const struct Curl_handler Curl_handler_https = {
  http_getsock_do,                      /* doing_getsock */
  ZERO_NULL,                            /* domore_getsock */
  ZERO_NULL,                            /* perform_getsock */
  ZERO_NULL,                            /* disconnect */
  http_disconnect,                      /* disconnect */
  ZERO_NULL,                            /* readwrite */
  PORT_HTTPS,                           /* defport */
  CURLPROTO_HTTPS,                      /* protocol */
@@ -179,6 +180,17 @@ CURLcode Curl_http_setup_conn(struct connectdata *conn)
  return CURLE_OK;
}

static CURLcode http_disconnect(struct connectdata *conn, bool dead_connection)
{
  struct HTTP *http = conn->data->req.protop;
  (void)dead_connection;
  if(http) {
    Curl_add_buffer_free(http->header_recvbuf);
    http->header_recvbuf = NULL; /* clear the pointer */
  }
  return CURLE_OK;
}

/*
 * checkheaders() checks the linked list of custom HTTP headers for a
 * particular header (prefix).
@@ -1043,6 +1055,16 @@ Curl_send_buffer *Curl_add_buffer_init(void)
  return calloc(1, sizeof(Curl_send_buffer));
}

/*
 * Curl_add_buffer_free() frees all associated resources.
 */
void Curl_add_buffer_free(Curl_send_buffer *buff)
{
  if(buff) /* deal with NULL input */
    free(buff->buffer);
  free(buff);
}

/*
 * Curl_add_buffer_send() sends a header buffer and frees all associated
 * memory.  Body data may be appended to the header data if desired.
@@ -1089,8 +1111,7 @@ CURLcode Curl_add_buffer_send(Curl_send_buffer *in,
  /* Curl_convert_to_network calls failf if unsuccessful */
  if(result) {
    /* conversion failed, free memory and return to the caller */
    free(in->buffer);
    free(in);
    Curl_add_buffer_free(in);
    return result;
  }

@@ -1192,8 +1213,7 @@ CURLcode Curl_add_buffer_send(Curl_send_buffer *in,
        conn->writechannel_inuse = FALSE;
    }
  }
  free(in->buffer);
  free(in);
  Curl_add_buffer_free(in);

  return result;
}
@@ -1472,13 +1492,16 @@ CURLcode Curl_http_done(struct connectdata *conn,
    return CURLE_OK;

  if(http->send_buffer) {
    Curl_send_buffer *buff = http->send_buffer;

    free(buff->buffer);
    free(buff);
    Curl_add_buffer_free(http->send_buffer);
    http->send_buffer = NULL; /* clear the pointer */
  }

  if(http->header_recvbuf) {
    DEBUGF(infof(data, "free header_recvbuf!!\n"));
    Curl_add_buffer_free(http->header_recvbuf);
    http->header_recvbuf = NULL; /* clear the pointer */
  }

  if(HTTPREQ_POST_FORM == data->set.httpreq) {
    data->req.bytecount = http->readbytecount + http->writebytecount;

+1 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ struct Curl_send_buffer {
typedef struct Curl_send_buffer Curl_send_buffer;

Curl_send_buffer *Curl_add_buffer_init(void);
void Curl_add_buffer_free(Curl_send_buffer *buff);
CURLcode Curl_add_bufferf(Curl_send_buffer *in, const char *fmt, ...);
CURLcode Curl_add_buffer(Curl_send_buffer *in, const void *inptr, size_t size);
CURLcode Curl_add_buffer_send(Curl_send_buffer *in,
+1 −1
Original line number Diff line number Diff line
@@ -85,8 +85,8 @@ static CURLcode http2_disconnect(struct connectdata *conn,
  DEBUGF(infof(conn->data, "HTTP/2 DISCONNECT starts now\n"));

  nghttp2_session_del(c->h2);

  Curl_safefree(c->inbuf);
  Curl_hash_clean(&c->streamsh);

  DEBUGF(infof(conn->data, "HTTP/2 DISCONNECT done\n"));

+4 −4
Original line number Diff line number Diff line
@@ -135,7 +135,7 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,

      host_port = aprintf("%s:%hu", hostname, remote_port);
      if(!host_port) {
        free(req_buffer);
        Curl_add_buffer_free(req_buffer);
        return CURLE_OUT_OF_MEMORY;
      }

@@ -155,7 +155,7 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
                  hostname, conn->bits.ipv6_ip?"]":"",
                  remote_port);
        if(!hostheader) {
          free(req_buffer);
          Curl_add_buffer_free(req_buffer);
          return CURLE_OUT_OF_MEMORY;
        }

@@ -163,7 +163,7 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
          host = aprintf("Host: %s\r\n", hostheader);
          if(!host) {
            free(hostheader);
            free(req_buffer);
            Curl_add_buffer_free(req_buffer);
            return CURLE_OUT_OF_MEMORY;
          }
        }
@@ -212,7 +212,7 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
          failf(data, "Failed sending CONNECT to proxy");
      }

      free(req_buffer);
      Curl_add_buffer_free(req_buffer);
      if(result)
        return result;

Loading