From 2873971d6251b7c1eb278df1ee2b944d7c3fcdba Mon Sep 17 00:00:00 2001 From: Daniel Gustafsson Date: Wed, 3 Oct 2018 00:56:29 +0200 Subject: memory: ensure to check allocation results The result of a memory allocation should always be checked, as we may run under memory pressure where even a small allocation can fail. This adds checking and error handling to a few cases where the allocation wasn't checked for success. In the ftp case, the freeing of the path variable is moved ahead of the allocation since there is little point in keeping it around across the strdup, and the separation makes for more readable code. In nwlib, the lock is aslo freed in the error path. Also bumps the copyright years on affected files. Closes #3084 Reviewed-by: Jay Satiro Reviewed-by: Daniel Stenberg --- lib/http2.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/http2.c') diff --git a/lib/http2.c b/lib/http2.c index 29edfba7a..ed47b73b2 100644 --- a/lib/http2.c +++ b/lib/http2.c @@ -957,6 +957,8 @@ static int on_header(nghttp2_session *session, const nghttp2_frame *frame, stream->push_headers_alloc = 10; stream->push_headers = malloc(stream->push_headers_alloc * sizeof(char *)); + if(!stream->push_headers) + return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; stream->push_headers_used = 0; } else if(stream->push_headers_used == -- cgit v1.2.3