Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
iSulad
提交
4f4d1743
I
iSulad
项目概览
openeuler
/
iSulad
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
iSulad
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4f4d1743
编写于
6月 02, 2020
作者:
L
lifeng68
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
layer store: fix double free
Signed-off-by:
N
lifeng68
<
lifeng68@huawei.com
>
上级
9e872e10
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
41 addition
and
59 deletion
+41
-59
src/cutils/utils_file.c
src/cutils/utils_file.c
+2
-2
src/image/oci/storage/layer_store/layer_store.c
src/image/oci/storage/layer_store/layer_store.c
+39
-57
未找到文件。
src/cutils/utils_file.c
浏览文件 @
4f4d1743
...
...
@@ -96,11 +96,11 @@ int util_path_remove(const char *path)
return
-
1
;
}
if
(
unlink
(
path
)
==
0
)
{
if
(
unlink
(
path
)
==
0
||
errno
==
ENOENT
)
{
return
0
;
}
saved_errno
=
errno
;
if
(
rmdir
(
path
)
==
0
)
{
if
(
rmdir
(
path
)
==
0
||
errno
==
ENOENT
)
{
return
0
;
}
if
(
errno
==
ENOTDIR
)
{
...
...
src/image/oci/storage/layer_store/layer_store.c
浏览文件 @
4f4d1743
...
...
@@ -902,11 +902,11 @@ static int update_mount_point(layer_t *l)
if
(
l
->
smount_point
==
NULL
)
{
l
->
smount_point
=
util_common_calloc_s
(
sizeof
(
storage_mount_point
));
}
if
(
l
->
smount_point
==
NULL
)
{
ERROR
(
"Out of memory"
);
return
-
1
;
}
}
d_meta
=
graphdriver_get_metadata
(
l
->
slayer
->
id
);
if
(
d_meta
==
NULL
)
{
...
...
@@ -915,9 +915,19 @@ static int update_mount_point(layer_t *l)
goto
out
;
}
if
(
d_meta
->
data
!=
NULL
)
{
free
(
l
->
smount_point
->
path
);
l
->
smount_point
->
path
=
util_strdup_s
(
d_meta
->
data
->
merged_dir
);
}
if
(
l
->
mount_point_json_path
==
NULL
)
{
l
->
mount_point_json_path
=
mountpoint_json_path
(
l
->
slayer
->
id
);
if
(
l
->
mount_point_json_path
==
NULL
)
{
ERROR
(
"Failed to get layer %s mount point json"
,
l
->
slayer
->
id
);
ret
=
-
1
;
goto
out
;
}
}
out:
free_container_inspect_graph_driver
(
d_meta
);
return
ret
;
...
...
@@ -1127,14 +1137,10 @@ free_out:
static
int
umount_helper
(
layer_t
*
l
,
bool
force
)
{
int
ret
=
0
;
int32_t
save_cnt
=
0
;
char
*
save_path
=
NULL
;
if
(
l
->
smount_point
==
NULL
)
{
return
0
;
}
save_cnt
=
l
->
smount_point
->
count
;
save_path
=
l
->
smount_point
->
path
;
if
(
!
force
&&
l
->
smount_point
->
count
>
1
)
{
l
->
smount_point
->
count
-=
1
;
...
...
@@ -1145,27 +1151,23 @@ static int umount_helper(layer_t *l, bool force)
ret
=
graphdriver_umount_layer
(
l
->
slayer
->
id
);
if
(
ret
!=
0
)
{
ERROR
(
"Call driver umount failed"
);
goto
err_out
;
ret
=
-
1
;
goto
out
;
}
l
->
smount_point
->
count
=
0
;
l
->
smount_point
->
path
=
NULL
;
save_json:
ret
=
save_mount_point
(
l
);
if
(
ret
!=
0
)
{
l
->
smount_point
->
count
=
save_cnt
;
l
->
smount_point
->
path
=
save_path
;
save_path
=
NULL
;
l
->
smount_point
->
count
+=
1
;
}
free
(
save_path
);
err_out:
out:
return
ret
;
}
int
layer_store_delete
(
const
char
*
id
)
{
layer_t
*
l
=
NULL
;
size_t
i
=
0
;
int
ret
=
0
;
char
*
tspath
=
NULL
;
...
...
@@ -1181,14 +1183,17 @@ int layer_store_delete(const char *id)
ERROR
(
"layer not known"
);
return
-
1
;
}
if
(
l
->
smount_point
!=
NULL
)
{
for
(;
i
<
l
->
smount_point
->
count
;
i
++
)
{
if
(
umount_helper
(
l
,
false
)
!=
0
)
{
if
(
umount_helper
(
l
,
true
)
!=
0
)
{
ret
=
-
1
;
ERROR
(
"Failed to umount layer %s"
,
l
->
slayer
->
id
);
goto
free_out
;
}
if
(
l
->
mount_point_json_path
!=
NULL
&&
util_path_remove
(
l
->
mount_point_json_path
)
!=
0
)
{
SYSERROR
(
"Can not remove mount point file of layer %s, just ignore."
,
l
->
mount_point_json_path
);
}
}
tspath
=
tar_split_path
(
l
->
slayer
->
id
);
if
(
tspath
!=
NULL
&&
util_path_remove
(
tspath
)
!=
0
)
{
SYSERROR
(
"Can not remove layer files, just ignore."
);
...
...
@@ -1432,66 +1437,43 @@ static char *mount_helper(layer_t *l, const struct layer_store_mount_opts *opts)
{
char
*
mount_point
=
NULL
;
int
nret
=
0
;
int32_t
save_cnt
=
0
;
char
*
save_path
=
NULL
;
struct
driver_mount_opts
*
d_opts
=
NULL
;
if
(
l
->
smount_point
==
NULL
)
{
l
->
smount_point
=
util_common_calloc_s
(
sizeof
(
storage_mount_point
));
if
(
l
->
smount_point
==
NULL
)
{
ERROR
(
"Out of memory"
);
return
NULL
;
}
}
if
(
l
->
mount_point_json_path
==
NULL
)
{
l
->
mount_point_json_path
=
mountpoint_json_path
(
l
->
slayer
->
id
);
if
(
l
->
mount_point_json_path
==
NULL
)
{
ERROR
(
"Failed to get layer %s mount point json"
,
l
->
slayer
->
id
);
nret
=
update_mount_point
(
l
);
if
(
nret
!=
0
)
{
ERROR
(
"Failed to update mount point"
);
return
NULL
;
}
}
save_cnt
=
l
->
smount_point
->
count
;
save_path
=
l
->
smount_point
->
path
;
if
(
l
->
smount_point
->
count
>
0
)
{
l
->
smount_point
->
count
+=
1
;
mount_point
=
util_strdup_s
(
save_path
);
ERROR
(
"layer %s mount count %d"
,
l
->
slayer
->
id
,
l
->
smount_point
->
count
);
mount_point
=
util_strdup_s
(
l
->
smount_point
->
path
);
goto
save_json
;
}
d_opts
=
fill_driver_mount_opts
(
opts
,
l
);
if
(
d_opts
==
NULL
)
{
ERROR
(
"Failed to fill layer %s driver mount opts"
,
l
->
slayer
->
id
);
goto
err_
out
;
goto
out
;
}
mount_point
=
graphdriver_mount_layer
(
l
->
slayer
->
id
,
d_opts
);
if
(
mount_point
==
NULL
)
{
ERROR
(
"Call driver mount: %s failed"
,
l
->
slayer
->
id
);
goto
err_
out
;
goto
out
;
}
l
->
smount_point
->
count
+=
1
;
l
->
smount_point
->
path
=
util_strdup_s
(
mount_point
);
save_json:
nret
=
save_mount_point
(
l
);
if
(
nret
!=
0
)
{
l
->
smount_point
->
count
=
save_cnt
;
free
(
l
->
smount_point
->
path
);
l
->
smount_point
->
path
=
save_path
;
save_path
=
NULL
;
goto
err_out
;
l
->
smount_point
->
count
-=
1
;
}
out:
free_graphdriver_mount_opts
(
d_opts
);
free
(
save_path
);
return
mount_point
;
err_out:
free_graphdriver_mount_opts
(
d_opts
);
free
(
mount_point
);
free
(
save_path
);
return
NULL
;
}
char
*
layer_store_mount
(
const
char
*
id
,
const
struct
layer_store_mount_opts
*
opts
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录