4 Star 0 Fork 3

src-openEuler/vhostmd

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0009-libmetrics-Fix-potential-leak-of-FILE-pointer.patch 2.09 KB
一键复制 编辑 原始数据 按行查看 历史
shenhy123 提交于 2021-09-01 09:53 +08:00 . Add vhostmd
From cba4dddebc56886034038f907085da3c6b50baab Mon Sep 17 00:00:00 2001
From: Jim Fehlig <[email protected]>
Date: Mon, 6 Jan 2020 18:59:18 -0700
Subject: [PATCH 09/19] libmetrics: Fix potential leak of FILE pointer
From coverity scan
vhostmd-1.1/libmetrics/libmetrics.c:892: alloc_fn: Storage is returned from allocation function "fopen".
vhostmd-1.1/libmetrics/libmetrics.c:892: var_assign: Assigning: "fp" = storage returned from "fopen(dest_file, "w")".
vhostmd-1.1/libmetrics/libmetrics.c:900: noescape: Resource "fp" is not freed or pointed-to in "fwrite".
vhostmd-1.1/libmetrics/libmetrics.c:909: leaked_storage: Variable "fp" going out of scope leaks the storage it points to.
907| free(response);
908|
909|-> return 0;
910|
911| error:
Signed-off-by: Jim Fehlig <[email protected]>
---
libmetrics/libmetrics.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/libmetrics/libmetrics.c b/libmetrics/libmetrics.c
index 0f4cf70..8819074 100644
--- a/libmetrics/libmetrics.c
+++ b/libmetrics/libmetrics.c
@@ -890,10 +890,11 @@ int dump_virtio_metrics(const char *dest_file)
FILE *fp = stdout;
char *response = NULL;
size_t len;
+ int ret = -1;
response = get_virtio_metrics();
if (response == NULL)
- goto error;
+ return -1;
len = strlen(response);
@@ -902,27 +903,24 @@ int dump_virtio_metrics(const char *dest_file)
if (fp == NULL) {
libmsg("%s(), unable to dump metrics: fopen(%s) %s\n",
__func__, dest_file, strerror(errno));
- goto error;
+ goto out;
}
}
if (fwrite(response, 1UL, len, fp) != len) {
libmsg("%s(), unable to export metrics to file:%s %s\n",
__func__, dest_file ? dest_file : "stdout", strerror(errno));
- goto error;
+ goto out;
}
- if (response)
- free(response);
+ ret = 0;
- return 0;
-
- error:
+out:
if (dest_file && fp)
fclose(fp);
if (response)
free(response);
- return -1;
+ return ret;
}
--
2.32.0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-openeuler/vhostmd.git
[email protected]:src-openeuler/vhostmd.git
src-openeuler
vhostmd
vhostmd
master

搜索帮助