JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.
If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.
If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.
| CodeSonar® 9.0p0 Hot Tips | CONFIDENTIAL | CodeSecure Inc |
既にクローズされているファイルやソケットを再度クローズしようとしています。
| クラス名 | Double Close | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 日本語クラス名 | 二重クローズ | ||||||||||||||||||
| クラス分類 | 信頼性 (reliability) | ||||||||||||||||||
| ニーモニック | IO.DC | ||||||||||||||||||
| カテゴリー |
|
||||||||||||||||||
| 対応言語 | C および C++ で利用可能です。 |
||||||||||||||||||
| 有効/無効設定 | このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル
(configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Double Close" |
同じファイルディスクリプタに対し2回 close() (もしくは同等の関数)が呼ばれた場合、クローズされたファイルのディスクリプタを再利用し、予期しない悪い結果を引き起こします。
#include <fcntl.h>
#include <unistd.h>
int double_close(const void *databuf, size_t datasize){
int mydesc;
int yourdesc;
ssize_t s;
int rv;
mydesc = open("myfile.txt", O_CREAT|O_RDONLY);
if (mydesc < 0){return -1;}
close(mydesc);
/* system may recycle the descriptor of the closed file
* giving yourdesc == mydesc */
yourdesc = open("yourfile.txt", O_CREAT|O_RDWR);
if (yourdesc < 0){return -2;}
/* if yourdesc == mydesc, equivalent to close(yourdesc) */
close(mydesc); /* 'Double Close' warning issued here */
/* if yourdesc == mydesc, may fail unexpectedly */
s = write(yourdesc, databuf, datasize);
close(yourdesc);
if (s < 0){return -3;}
return 0;
}
同じファイルポインタに対し2回 fclose() (もしくは同等の関数)が呼ばれた場合、ポインタを2回解放したことによる結果と同様のメモリの破壊の可能性を含め、予期しない振る舞いを起こします。
CodeSonar ships with library models that allow it to functions such as libc close() and Win32 FlsFree() that close a file or socket. If one of these functions is called on a file or socket that is already closed, a warning will be issued.
If you have created a custom library model for some function f() in terms of one of these existing models, calls to f() will also be capable of triggering Double Close warnings.
設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。