如果在fopen()之后忘记fclose(),是否有任何测试工具可以自动检测到它? [英] If forget to fclose() after fopen(), is there any testing tool who can detect it automatically?

查看:82
本文介绍了如果在fopen()之后忘记fclose(),是否有任何测试工具可以自动检测到它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

小组!

我这里有一个问题:


我们都知道fclose()必须在文件操作后调用

避免出现意外错误。但是有些情况下你忘记了这么做!
就像内存操作中发生的那样,每个人都知道重要性



释放分配的内存,但是时间确实有内存泄漏



时间!对于内存泄漏的情况,有很多测试工具可以自动检测它,例如Rational Purify或其他免费的b $ b。


所以我的问题是:那里有没有任何测试工具可以

检测

自动忘记fclose缺陷?


我搜索过谷歌页面和群组,但似乎没有提示!


任何帮助将不胜感激!

Hi, Group!
I got one question here:

We all know that fclose() must be called after file operations to
avoid unexpected errors.But there are really cases when you forget to
do that!Just
like what happens in memory operations, everyone knows the importance
of
freeing the allocated memory, but there do have memory leaks from time
to
time! For the memory leak case, there are lots of testing tools to
detect it
automatically like Rational Purify or other free ones.

So my question is: is there any testing tool right there which can
detect
forgetting-fclose defects automatically?

I have searched google pages and groups but seem to get no hint!

Any help will be greatly appreciated!

推荐答案

lihua写道:
我们都知道fclose()必须在文件操作后调用以避免意外错误。但是有些情况下你忘记了
那样做!就像在内存操作中发生的事情一样,每个人都知道释放已分配内存的重要性,但有时会出现内存泄漏!对于内存泄漏情况,有很多测试工具可以像Rational Purify或其他免费的那样自动检测它。

所以我的问题是:那里有没有任何测试工具可以
自动检测遗忘fclose缺陷?
We all know that fclose() must be called after file operations to
avoid unexpected errors.But there are really cases when you forget to
do that! Just like what happens in memory operations, everyone knows the
importance of freeing the allocated memory, but there do have memory leaks
from time to time! For the memory leak case, there are lots of testing tools
to detect it automatically like Rational Purify or other free ones.

So my question is: is there any testing tool right there which can
detect forgetting-fclose defects automatically?




在大多数C库中,fopen()为FILE *结构分配内存

它返回期望fclose()解除分配。换句话说,

最好的工具就像Purify。


-

Paul Hsieh
http://www.pobox.com/~qed/
< a rel =nofollowhref =http://bstring.sf.net/target =_ blank> http://bstring.sf.net/



In most C libraries, fopen() allocates memory for the FILE * structure
it returned expecting fclose() to deallocate it. In other words, the
best tool is something like Purify.

--
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/


您好

您可以使用dev合作伙伴..找到这样的

问题可能会有用

Mayur

Hi
You can use dev partner .. it may be useful to find such kind of
problems
Mayur


lihua写道:

我们都知道fclose()必须在文件操作后调用
避免意外错误。但是有些情况下你会忘记这样做!就像在内存操作中发生的事情一样,每个人都知道释放已分配内存的重要性,但确实如此有时会发生内存泄漏!对于内存泄漏情况,
有很多测试工具可以像Rational Purify或其他免费的那样自动检测它。

所以我的问题是:有没有任何测试工具在那里哪个可以自动检测忘记错误?

We all know that fclose() must be called after file operations to
avoid unexpected errors.But there are really cases when you forget
to do that!Just like what happens in memory operations, everyone
knows the importance of freeing the allocated memory, but there do
have memory leaks from time to time! For the memory leak case,
there are lots of testing tools to detect it automatically like
Rational Purify or other free ones.

So my question is: is there any testing tool right there which can
detect forgetting-fclose defects automatically?




如果你跟踪你在做什么那么应该没有

问题。但是如果你需要保护自己免受

邋iness的影响,试试这个:


1.无论你在哪里声明FILE *变量,都要将它初始化为NULL。 br />
2.确保该范围有一个退出点。

3.在该出口处,插入if(f)fclose(f),其中f为文件*

变量。


-

"如果你想通过groups.google.com发布后续信息,不要使用

破碎的回复链接在文章的底部。点击

" show options"在文章的顶部,然后点击

回复在文章标题的底部。 - Keith Thompson



If you keep track of what you are doing there should be no
problem. However if you need to protect against your own
sloppiness, try this:

1. Wherever you declare the FILE* variable, initialize it to NULL.
2. Ensure that that scope has a single exit point.
3. At that exit, insert "if (f) fclose(f)", where f is the FILE*
variable.

--
"If you want to post a followup via groups.google.com, don''t use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson


这篇关于如果在fopen()之后忘记fclose(),是否有任何测试工具可以自动检测到它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆