Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenCV
opencv
提交
673eb2b0
O
opencv
项目概览
OpenCV
/
opencv
上一次同步 9 个月
通知
992
Star
71100
Fork
55581
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
673eb2b0
编写于
3月 24, 2020
作者:
A
Alexander Alekhin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
core(persistence): fix resource leaks - force closing files
上级
4dfa798e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
75 addition
and
7 deletion
+75
-7
modules/core/src/persistence.cpp
modules/core/src/persistence.cpp
+14
-7
modules/core/test/test_io.cpp
modules/core/test/test_io.cpp
+61
-0
未找到文件。
modules/core/src/persistence.cpp
浏览文件 @
673eb2b0
...
...
@@ -407,14 +407,13 @@ public:
else
if
(
fmt
==
FileStorage
::
FORMAT_JSON
)
puts
(
"}
\n
"
);
}
closeFile
();
if
(
mem_mode
&&
out
)
{
*
out
=
cv
::
String
(
outbuf
.
begin
(),
outbuf
.
end
());
}
init
();
}
closeFile
();
init
();
}
void
analyze_file_name
(
const
std
::
string
&
file_name
,
std
::
vector
<
std
::
string
>&
params
)
...
...
@@ -1825,10 +1824,18 @@ FileStorage::~FileStorage()
bool
FileStorage
::
open
(
const
String
&
filename
,
int
flags
,
const
String
&
encoding
)
{
bool
ok
=
p
->
open
(
filename
.
c_str
(),
flags
,
encoding
.
c_str
());
if
(
ok
)
state
=
FileStorage
::
NAME_EXPECTED
+
FileStorage
::
INSIDE_MAP
;
return
ok
;
try
{
bool
ok
=
p
->
open
(
filename
.
c_str
(),
flags
,
encoding
.
c_str
());
if
(
ok
)
state
=
FileStorage
::
NAME_EXPECTED
+
FileStorage
::
INSIDE_MAP
;
return
ok
;
}
catch
(...)
{
release
();
throw
;
// re-throw
}
}
bool
FileStorage
::
isOpened
()
const
{
return
p
->
is_opened
;
}
...
...
modules/core/test/test_io.cpp
浏览文件 @
673eb2b0
...
...
@@ -1711,4 +1711,65 @@ TEST(Core_InputOutput, FileStorage_JSON_VeryLongLines)
}
}
TEST
(
Core_InputOutput
,
FileStorage_empty_16823
)
{
std
::
string
fname
=
tempfile
(
"test_fs_empty.yml"
);
{
// create empty file
std
::
ofstream
f
(
fname
.
c_str
(),
std
::
ios
::
out
);
}
try
{
FileStorage
fs
(
fname
,
FileStorage
::
READ
);
ADD_FAILURE
()
<<
"Exception must be thrown for empty file."
;
}
catch
(
const
cv
::
Exception
&
)
{
// expected way
// closed files can be checked manually through 'strace'
}
catch
(
const
std
::
exception
&
e
)
{
ADD_FAILURE
()
<<
"Unexpected exception: "
<<
e
.
what
();
}
catch
(...)
{
ADD_FAILURE
()
<<
"Unexpected unknown C++ exception"
;
}
EXPECT_EQ
(
0
,
remove
(
fname
.
c_str
()));
}
TEST
(
Core_InputOutput
,
FileStorage_open_empty_16823
)
{
std
::
string
fname
=
tempfile
(
"test_fs_open_empty.yml"
);
{
// create empty file
std
::
ofstream
f
(
fname
.
c_str
(),
std
::
ios
::
out
);
}
FileStorage
fs
;
try
{
fs
.
open
(
fname
,
FileStorage
::
READ
);
ADD_FAILURE
()
<<
"Exception must be thrown for empty file."
;
}
catch
(
const
cv
::
Exception
&
)
{
// expected way
// closed files can be checked manually through 'strace'
}
catch
(
const
std
::
exception
&
e
)
{
ADD_FAILURE
()
<<
"Unexpected exception: "
<<
e
.
what
();
}
catch
(...)
{
ADD_FAILURE
()
<<
"Unexpected unknown C++ exception"
;
}
EXPECT_EQ
(
0
,
remove
(
fname
.
c_str
()));
}
}}
// namespace
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录