Browse Source

utils: Don't leak memory of pkg_realloc returns NULL

Carsten Bock 10 năm trước cách đây
mục cha
commit
641b7b2371
1 tập tin đã thay đổi với 3 bổ sung2 xóa
  1. 3 2
      modules/utils/functions.c

+ 3 - 2
modules/utils/functions.c

@@ -58,13 +58,14 @@ size_t write_function( void *ptr, size_t size, size_t nmemb, void *stream_ptr)
 {
 	http_res_stream_t *stream = (http_res_stream_t *) stream_ptr;
 
-	stream->buf = (char *) pkg_realloc(stream->buf, stream->curr_size + 
+	char *tmp = (char *) pkg_realloc(stream->buf, stream->curr_size + 
 			(size * nmemb));
 
-	if (stream->buf == NULL) {
+	if (tmp == NULL) {
 		LM_ERR("cannot allocate memory for stream\n");
 		return CURLE_WRITE_ERROR;
 	}
+	stream->buf = tmp;
 
 	memcpy(&stream->buf[stream->pos], (char *) ptr, (size * nmemb));