From 460f3b218cd726e7645c26ebeb8ed82316f72959 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 17 Aug 2021 17:38:16 +0000 Subject: [PATCH] enhanced HawkStd::SourceFile()/HawkStd::SourceString() to detach early from hawk when open() fails --- hawk/lib/HawkStd.cpp | 36 ++++++++++++++++++++++++++++++++---- hawk/pkgs/hawk.spec.in | 2 +- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/hawk/lib/HawkStd.cpp b/hawk/lib/HawkStd.cpp index 9f7aa27f..e3db3c30 100644 --- a/hawk/lib/HawkStd.cpp +++ b/hawk/lib/HawkStd.cpp @@ -1255,6 +1255,8 @@ int HawkStd::SourceFile::open (Data& io) if (io.isMaster()) { + bool hawk_set_here = false; + // open the main source file. 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); #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')) @@ -1290,7 +1298,15 @@ int HawkStd::SourceFile::open (Data& io) io, HAWK_NULL, HAWK_SIO_STDOUT, HAWK_SIO_WRITE | HAWK_SIO_CREATE | 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 { @@ -1300,7 +1316,15 @@ int HawkStd::SourceFile::open (Data& io) (HAWK_SIO_READ | HAWK_SIO_IGNOREECERR | HAWK_SIO_KEEPPATH): (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); @@ -1434,7 +1458,11 @@ int HawkStd::SourceString::open (Data& io) this->str = hawk_dupbcstr(this->_hawk, (hawk_bch_t*)this->_str, HAWK_NULL); #endif } - if (!this->str) return -1; + if (!this->str) + { + this->_hawk = HAWK_NULL; + return -1; + } } this->ptr = this->str; diff --git a/hawk/pkgs/hawk.spec.in b/hawk/pkgs/hawk.spec.in index 31806f53..30e4828d 100644 --- a/hawk/pkgs/hawk.spec.in +++ b/hawk/pkgs/hawk.spec.in @@ -48,7 +48,7 @@ CFLAGS="${RPM_OPT_FLAGS} -fPIC" CXXFLAGS="${RPM_OPT_FLAGS} -fPIC" ./configure \ --enable-pthread-flags=yes \ --enable-libltdl=no \ --enable-libunwind=no \ - --enable-mod=mysql=yes \ + --enable-mod-mysql=yes \ --enable-mod-uci=no ##CC=gcc44 CXX=g++44 make