Skip to content

Commit

Permalink
Frontport more fixes for bug CORE-2934 : Memory leak in FB2.5 trace p…
Browse files Browse the repository at this point in the history
…lugin
  • Loading branch information
hvlad committed Mar 27, 2010
1 parent f458d09 commit b8bffbd
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 42 deletions.
5 changes: 5 additions & 0 deletions src/jrd/SimilarToMatcher.h
Expand Up @@ -78,6 +78,11 @@ class SimilarToMatcher : public Jrd::BaseSimilarToMatcher
const UCHAR* patternStr, SLONG patternLen,
CharType escapeChar, bool useEscape, bool forSubstring);

~Evaluator()
{
delete[] branches;
}

bool getResult();
bool processNextChunk(const UCHAR* data, SLONG dataLen);
void reset();
Expand Down
6 changes: 4 additions & 2 deletions src/utilities/ntrace/TraceConfiguration.cpp
Expand Up @@ -146,13 +146,15 @@ void TraceCfgReader::readConfig()
bool regExpOk = false;
try
{
Jrd::TextType* textType = TraceUnicodeUtils::getUnicodeTextType();

#ifdef WIN_NT // !CASE_SENSITIVITY
typedef Jrd::UpcaseConverter<SystemToUtf8Converter<> > SimilarConverter;
#else
typedef SystemToUtf8Converter<> SimilarConverter;
#endif

UnicodeCollationHolder unicodeCollation(*getDefaultMemoryPool());
Jrd::TextType *textType = unicodeCollation.getTextType();

SimilarToMatcher<ULONG, Jrd::CanonicalConverter<SimilarConverter> > matcher(
*getDefaultMemoryPool(), textType, (const UCHAR*) pattern.c_str(),
pattern.length(), '\\', true, false);
Expand Down
6 changes: 3 additions & 3 deletions src/utilities/ntrace/TracePluginImpl.cpp
Expand Up @@ -30,7 +30,6 @@
#include <math.h>

#include "TracePluginImpl.h"
#include "TraceUnicodeUtils.h"
#include "PluginLogWriter.h"
#include "os/platform.h"
#include "../../jrd/req.h"
Expand Down Expand Up @@ -117,7 +116,8 @@ TracePluginImpl::TracePluginImpl(const TracePluginConfig &configuration, TraceIn
connections(getDefaultMemoryPool()),
transactions(getDefaultMemoryPool()),
statements(getDefaultMemoryPool()),
services(getDefaultMemoryPool())
services(getDefaultMemoryPool()),
unicodeCollation(*getDefaultMemoryPool())
{
const char* ses_name = initInfo->getTraceSessionName();
session_name = ses_name && *ses_name ? ses_name : " ";
Expand All @@ -140,7 +140,7 @@ TracePluginImpl::TracePluginImpl(const TracePluginConfig &configuration, TraceIn
PluginLogWriter(logname.c_str(), config.max_log_size * 1024 * 1024);
}

Jrd::TextType* textType = TraceUnicodeUtils::getUnicodeTextType();
Jrd::TextType *textType = unicodeCollation.getTextType();

// Compile filtering regular expressions
if (config.include_filter.hasData())
Expand Down
2 changes: 2 additions & 0 deletions src/utilities/ntrace/TracePluginImpl.h
Expand Up @@ -31,6 +31,7 @@

#include "../../jrd/ntrace.h"
#include "TracePluginConfig.h"
#include "TraceUnicodeUtils.h"
#include "../../jrd/intl_classes.h"
#include "../../jrd/evl_string.h"
#include "../../jrd/TextType.h"
Expand Down Expand Up @@ -165,6 +166,7 @@ class TracePluginImpl
// Lock for log rotation
Firebird::RWLock renameLock;

UnicodeCollationHolder unicodeCollation;
Firebird::AutoPtr<Firebird::SimilarToMatcher<UCHAR, Jrd::UpcaseConverter<> > >
include_matcher, exclude_matcher;

Expand Down
55 changes: 21 additions & 34 deletions src/utilities/ntrace/TraceUnicodeUtils.cpp
Expand Up @@ -28,52 +28,39 @@


#include "TraceUnicodeUtils.h"
#include "../../common/classes/init.h"
#include "../../jrd/unicode_util.h"

using namespace Firebird;

namespace
UnicodeCollationHolder::UnicodeCollationHolder(MemoryPool& pool)
{
class UnicodeCollationHolder
{
private:
charset cs;
texttype tt;
AutoPtr<Jrd::CharSet> charSet;
AutoPtr<Jrd::TextType> textType;
cs = FB_NEW(pool) charset;
tt = FB_NEW(pool) texttype;

public:
UnicodeCollationHolder(MemoryPool&)
{
IntlUtil::initUtf8Charset(&cs);
IntlUtil::initUtf8Charset(cs);

string collAttributes("ICU-VERSION=");
collAttributes += Jrd::UnicodeUtil::DEFAULT_ICU_VERSION;
IntlUtil::setupIcuAttributes(&cs, collAttributes, "", collAttributes);
string collAttributes("ICU-VERSION=");
collAttributes += Jrd::UnicodeUtil::DEFAULT_ICU_VERSION;
IntlUtil::setupIcuAttributes(cs, collAttributes, "", collAttributes);

UCharBuffer collAttributesBuffer;
collAttributesBuffer.push(reinterpret_cast<const UCHAR*>(collAttributes.c_str()),
collAttributes.length());
UCharBuffer collAttributesBuffer;
collAttributesBuffer.push(reinterpret_cast<const UCHAR*>(collAttributes.c_str()),
collAttributes.length());

if (!IntlUtil::initUnicodeCollation(&tt, &cs, "UNICODE", 0, collAttributesBuffer, string()))
fatal_exception::raiseFmt("cannot initialize UNICODE collation to use in trace plugin");
if (!IntlUtil::initUnicodeCollation(tt, cs, "UNICODE", 0, collAttributesBuffer, string()))
fatal_exception::raiseFmt("cannot initialize UNICODE collation to use in trace plugin");

charSet = Jrd::CharSet::createInstance(*getDefaultMemoryPool(), 0, &cs);
textType = FB_NEW(*getDefaultMemoryPool()) Jrd::TextType(0, &tt, charSet);
}

Jrd::TextType* getTextType()
{
return textType;
}
};
charSet = Jrd::CharSet::createInstance(pool, 0, cs);
textType = FB_NEW(pool) Jrd::TextType(0, tt, charSet);
}

static InitInstance<UnicodeCollationHolder> unicodeCollation;
UnicodeCollationHolder::~UnicodeCollationHolder()
{
fb_assert(tt->texttype_fn_destroy);

if (tt->texttype_fn_destroy)
tt->texttype_fn_destroy(tt);

Jrd::TextType* TraceUnicodeUtils::getUnicodeTextType()
{
return unicodeCollation().getTextType();
// cs should be deleted by texttype_fn_destroy call above
delete tt;
}
15 changes: 12 additions & 3 deletions src/utilities/ntrace/TraceUnicodeUtils.h
Expand Up @@ -32,12 +32,21 @@
#include "../../common/classes/fb_string.h"
#include "../../jrd/intl_classes.h"
#include "../../jrd/TextType.h"
#include "../../jrd/unicode_util.h"


class TraceUnicodeUtils
class UnicodeCollationHolder
{
private:
charset *cs;
texttype *tt;
Firebird::AutoPtr<Jrd::CharSet> charSet;
Firebird::AutoPtr<Jrd::TextType> textType;

public:
static Jrd::TextType* getUnicodeTextType();
UnicodeCollationHolder(Firebird::MemoryPool& pool);
~UnicodeCollationHolder();

Jrd::TextType* getTextType() { return textType; };
};


Expand Down

0 comments on commit b8bffbd

Please sign in to comment.