enhanced HawkStd::SourceFile()/HawkStd::SourceString() to detach early from hawk when open() fails

This commit is contained in:
hyung-hwan 2021-08-17 17:38:16 +00:00
parent 05f99d1304
commit 460f3b218c
2 changed files with 33 additions and 5 deletions

View File

@ -1255,6 +1255,8 @@ int HawkStd::SourceFile::open (Data& io)
if (io.isMaster()) if (io.isMaster())
{ {
bool hawk_set_here = false;
// open the main source file. // open the main source file.
if (!this->name) if (!this->name)
{ {
@ -1276,7 +1278,13 @@ int HawkStd::SourceFile::open (Data& io)
this->name = hawk_dupbcstr(this->_hawk, (hawk_bch_t*)this->_name, HAWK_NULL); this->name = hawk_dupbcstr(this->_hawk, (hawk_bch_t*)this->_name, HAWK_NULL);
#endif #endif
} }
if (!this->name) return -1; if (!this->name)
{
this->_hawk = HAWK_NULL;
return -1;
}
hawk_set_here = true;
} }
if (this->name[0] == HAWK_T('-') && this->name[1] == HAWK_T('\0')) if (this->name[0] == HAWK_T('-') && this->name[1] == HAWK_T('\0'))
@ -1290,7 +1298,15 @@ int HawkStd::SourceFile::open (Data& io)
io, HAWK_NULL, HAWK_SIO_STDOUT, io, HAWK_NULL, HAWK_SIO_STDOUT,
HAWK_SIO_WRITE | HAWK_SIO_CREATE | HAWK_SIO_WRITE | HAWK_SIO_CREATE |
HAWK_SIO_TRUNCATE | HAWK_SIO_IGNOREECERR | HAWK_SIO_LINEBREAK); HAWK_SIO_TRUNCATE | HAWK_SIO_IGNOREECERR | HAWK_SIO_LINEBREAK);
if (sio == HAWK_NULL) return -1; if (sio == HAWK_NULL)
{
if (hawk_set_here)
{
hawk_freemem (this->_hawk, this->name);
this->_hawk = HAWK_NULL;
}
return -1;
}
} }
else else
{ {
@ -1300,7 +1316,15 @@ int HawkStd::SourceFile::open (Data& io)
(HAWK_SIO_READ | HAWK_SIO_IGNOREECERR | HAWK_SIO_KEEPPATH): (HAWK_SIO_READ | HAWK_SIO_IGNOREECERR | HAWK_SIO_KEEPPATH):
(HAWK_SIO_WRITE | HAWK_SIO_CREATE | HAWK_SIO_TRUNCATE | HAWK_SIO_IGNOREECERR)) (HAWK_SIO_WRITE | HAWK_SIO_CREATE | HAWK_SIO_TRUNCATE | HAWK_SIO_IGNOREECERR))
); );
if (sio == HAWK_NULL) return -1; if (sio == HAWK_NULL)
{
if (hawk_set_here)
{
hawk_freemem (this->_hawk, this->name);
this->_hawk = HAWK_NULL;
}
return -1;
}
} }
if (this->cmgr) hawk_sio_setcmgr (sio, this->cmgr); if (this->cmgr) hawk_sio_setcmgr (sio, this->cmgr);
@ -1434,7 +1458,11 @@ int HawkStd::SourceString::open (Data& io)
this->str = hawk_dupbcstr(this->_hawk, (hawk_bch_t*)this->_str, HAWK_NULL); this->str = hawk_dupbcstr(this->_hawk, (hawk_bch_t*)this->_str, HAWK_NULL);
#endif #endif
} }
if (!this->str) return -1; if (!this->str)
{
this->_hawk = HAWK_NULL;
return -1;
}
} }
this->ptr = this->str; this->ptr = this->str;

View File

@ -48,7 +48,7 @@ CFLAGS="${RPM_OPT_FLAGS} -fPIC" CXXFLAGS="${RPM_OPT_FLAGS} -fPIC" ./configure \
--enable-pthread-flags=yes \ --enable-pthread-flags=yes \
--enable-libltdl=no \ --enable-libltdl=no \
--enable-libunwind=no \ --enable-libunwind=no \
--enable-mod=mysql=yes \ --enable-mod-mysql=yes \
--enable-mod-uci=no ##CC=gcc44 CXX=g++44 --enable-mod-uci=no ##CC=gcc44 CXX=g++44
make make