浏览代码

[http] Add missing check for memory allocation failure

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 7 年前
父节点
当前提交
f17cf0ecd0
共有 1 个文件被更改,包括 5 次插入0 次删除
  1. 5
    0
      src/net/tcp/httpconn.c

+ 5
- 0
src/net/tcp/httpconn.c 查看文件

@@ -277,6 +277,10 @@ int http_connect ( struct interface *xfer, struct uri *uri ) {
277 277
 
278 278
 	/* Allocate and initialise structure */
279 279
 	conn = zalloc ( sizeof ( *conn ) );
280
+	if ( ! conn ) {
281
+		rc = -ENOMEM;
282
+		goto err_alloc;
283
+	}
280 284
 	ref_init ( &conn->refcnt, http_conn_free );
281 285
 	conn->uri = uri_get ( uri );
282 286
 	conn->scheme = scheme;
@@ -310,5 +314,6 @@ int http_connect ( struct interface *xfer, struct uri *uri ) {
310 314
 		conn->scheme->name, conn->uri->host, port, strerror ( rc ) );
311 315
 	http_conn_close ( conn, rc );
312 316
 	ref_put ( &conn->refcnt );
317
+ err_alloc:
313 318
 	return rc;
314 319
 }

正在加载...
取消
保存