Bug 477174 - Always release this file descriptor. r=brendan

This commit is contained in:
Blake Kaplan 2009-02-06 14:28:48 -08:00
Родитель 3bc711a48b
Коммит bac3e197a2
1 изменённых файлов: 24 добавлений и 4 удалений

Просмотреть файл

@ -358,6 +358,26 @@ js_NewContext(JSRuntime *rt, size_t stackChunkSize)
#if defined DEBUG && defined XP_UNIX #if defined DEBUG && defined XP_UNIX
# include <stdio.h> # include <stdio.h>
class AutoFile {
public:
AutoFile() : mFp(NULL) {}
~AutoFile() {
if (mFp)
fclose(mFp);
}
FILE *open(const char *fname, const char *mode) {
return mFp = fopen(fname, mode);
}
operator FILE *() {
return mFp;
}
private:
FILE *mFp;
};
static void static void
DumpEvalCacheMeter(JSContext *cx) DumpEvalCacheMeter(JSContext *cx)
{ {
@ -371,18 +391,18 @@ DumpEvalCacheMeter(JSContext *cx)
}; };
JSEvalCacheMeter *ecm = &JS_CACHE_LOCUS(cx)->evalCacheMeter; JSEvalCacheMeter *ecm = &JS_CACHE_LOCUS(cx)->evalCacheMeter;
static FILE *fp; static AutoFile fp;
if (!fp) { if (!fp) {
fp = fopen("/tmp/evalcache.stats", "w"); fp.open("/tmp/evalcache.stats", "w");
if (!fp) if (!fp)
return; return;
} }
fprintf(fp, "eval cache meter (%p):\n", fprintf(fp, "eval cache meter (%p):\n",
#ifdef JS_THREADSAFE #ifdef JS_THREADSAFE
cx->thread (void *) cx->thread
#else #else
cx->runtime (void *) cx->runtime
#endif #endif
); );
for (uintN i = 0; i < JS_ARRAY_LENGTH(table); ++i) { for (uintN i = 0; i < JS_ARRAY_LENGTH(table); ++i) {