Avoid possible double-free and make nghttp2_buf{s}_free(NULL) success

This commit is contained in:
Tatsuhiro Tsujikawa 2014-08-23 11:16:49 +09:00
parent 679a0a0fa1
commit cfee9cab36
1 changed files with 16 additions and 0 deletions

View File

@ -45,7 +45,12 @@ int nghttp2_buf_init2(nghttp2_buf *buf, size_t initial)
void nghttp2_buf_free(nghttp2_buf *buf) void nghttp2_buf_free(nghttp2_buf *buf)
{ {
if(buf == NULL) {
return;
}
free(buf->begin); free(buf->begin);
buf->begin = NULL;
} }
int nghttp2_buf_reserve(nghttp2_buf *buf, size_t new_cap) int nghttp2_buf_reserve(nghttp2_buf *buf, size_t new_cap)
@ -168,6 +173,10 @@ void nghttp2_bufs_free(nghttp2_bufs *bufs)
{ {
nghttp2_buf_chain *chain, *next_chain; nghttp2_buf_chain *chain, *next_chain;
if(bufs == NULL) {
return;
}
for(chain = bufs->head; chain;) { for(chain = bufs->head; chain;) {
next_chain = chain->next; next_chain = chain->next;
@ -175,6 +184,8 @@ void nghttp2_bufs_free(nghttp2_bufs *bufs)
chain = next_chain; chain = next_chain;
} }
bufs->head = NULL;
} }
int nghttp2_bufs_wrap_init(nghttp2_bufs *bufs, uint8_t *begin, size_t len) int nghttp2_bufs_wrap_init(nghttp2_bufs *bufs, uint8_t *begin, size_t len)
@ -205,7 +216,12 @@ int nghttp2_bufs_wrap_init(nghttp2_bufs *bufs, uint8_t *begin, size_t len)
void nghttp2_bufs_wrap_free(nghttp2_bufs *bufs) void nghttp2_bufs_wrap_free(nghttp2_bufs *bufs)
{ {
if(bufs == NULL) {
return;
}
free(bufs->head); free(bufs->head);
bufs->head = NULL;
} }
void nghttp2_bufs_seek_last_present(nghttp2_bufs *bufs) void nghttp2_bufs_seek_last_present(nghttp2_bufs *bufs)