Skip to content

Commit

Permalink
nghttp2_hd_*_new: Leave *inflater_ptr or *deflater_ptr untouched on f…
Browse files Browse the repository at this point in the history
…ailure
  • Loading branch information
tatsuhiro-t committed Jun 25, 2014
1 parent 55c338d commit 16fef22
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
4 changes: 4 additions & 0 deletions lib/includes/nghttp2/nghttp2.h
Original file line number Diff line number Diff line change
Expand Up @@ -2784,6 +2784,8 @@ typedef struct nghttp2_hd_deflater nghttp2_hd_deflater;
* The |deflate_hd_table_bufsize_max| is the upper bound of header
* table size the deflater will use.
*
* If this function fails, |*deflater_ptr| is left untouched.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
Expand Down Expand Up @@ -2892,6 +2894,8 @@ typedef struct nghttp2_hd_inflater nghttp2_hd_inflater;
*
* Initializes |*inflater_ptr| for inflating name/values pairs.
*
* If this function fails, |*inflater_ptr| is left untouched.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
Expand Down
34 changes: 28 additions & 6 deletions lib/nghttp2_hd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1315,13 +1315,24 @@ size_t nghttp2_hd_deflate_bound(nghttp2_hd_deflater *deflater,
int nghttp2_hd_deflate_new(nghttp2_hd_deflater **deflater_ptr,
size_t deflate_hd_table_bufsize_max)
{
*deflater_ptr = malloc(sizeof(nghttp2_hd_deflater));
int rv;
nghttp2_hd_deflater *deflater;

deflater = malloc(sizeof(nghttp2_hd_deflater));

if(*deflater_ptr == NULL) {
if(deflater == NULL) {
return NGHTTP2_ERR_NOMEM;
}

return nghttp2_hd_deflate_init2(*deflater_ptr, deflate_hd_table_bufsize_max);
rv = nghttp2_hd_deflate_init2(deflater, deflate_hd_table_bufsize_max);

if(rv != 0) {
return rv;
}

*deflater_ptr = deflater;

return 0;
}

void nghttp2_hd_deflate_del(nghttp2_hd_deflater *deflater)
Expand Down Expand Up @@ -2015,13 +2026,24 @@ int nghttp2_hd_inflate_end_headers(nghttp2_hd_inflater *inflater)

int nghttp2_hd_inflate_new(nghttp2_hd_inflater **inflater_ptr)
{
*inflater_ptr = malloc(sizeof(nghttp2_hd_inflater));
int rv;
nghttp2_hd_inflater *inflater;

inflater = malloc(sizeof(nghttp2_hd_inflater));

if(*inflater_ptr == NULL) {
if(inflater == NULL) {
return NGHTTP2_ERR_NOMEM;
}

return nghttp2_hd_inflate_init(*inflater_ptr);
rv = nghttp2_hd_inflate_init(inflater);

if(rv != 0) {
return rv;
}

*inflater_ptr = inflater;

return 0;
}

void nghttp2_hd_inflate_del(nghttp2_hd_inflater *inflater)
Expand Down

0 comments on commit 16fef22

Please sign in to comment.