From 0a05caf29f2242d28ae38097f2aa6bda59a66e7b Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 1 Mar 2013 00:29:48 +0100 Subject: [PATCH] - Fix memory leak modified: storage/connect/connect.cc - GCC requires template<> headers modified: storage/connect/value.cpp --- storage/connect/connect.cc | 1 + storage/connect/value.cpp | 260 ++++++++++++++++++++----------------- 2 files changed, 139 insertions(+), 122 deletions(-) diff --git a/storage/connect/connect.cc b/storage/connect/connect.cc index d24bec39c34..d3e8f77ed8f 100644 --- a/storage/connect/connect.cc +++ b/storage/connect/connect.cc @@ -82,6 +82,7 @@ PGLOBAL CntExit(PGLOBAL g) } // endif free(dup); + free(g->Activityp); g= NULL; } // endif g diff --git a/storage/connect/value.cpp b/storage/connect/value.cpp index 988f1d035b0..66dd204f814 100644 --- a/storage/connect/value.cpp +++ b/storage/connect/value.cpp @@ -508,6 +508,7 @@ int TYPVAL::GetValLen(void) return sprintf(c, Fmt, Tval); } // end of GetValLen +template <> int TYPVAL::GetValLen(void) { char c[32]; @@ -534,15 +535,19 @@ bool TYPVAL::SetValue_pval(PVAL valp, bool chktype) return false; } // end of SetValue +template <> short TYPVAL::GetTypedValue(PVAL valp) {return valp->GetShortValue();} +template <> int TYPVAL::GetTypedValue(PVAL valp) {return valp->GetIntValue();} +template <> longlong TYPVAL::GetTypedValue(PVAL valp) {return valp->GetBigintValue();} +template <> double TYPVAL::GetTypedValue(PVAL valp) {return valp->GetFloatValue();} @@ -587,6 +592,7 @@ void TYPVAL::SetValue_char(char *p, int n) Null = false; } // end of SetValue +template <> void TYPVAL::SetValue_char(char *p, int n) { char *p2, buf[32]; @@ -614,9 +620,13 @@ void TYPVAL::SetValue_psz(PSZ s) Null = false; } // end of SetValue +template <> int TYPVAL::GetTypedValue(PSZ s) {return atol(s);} +template <> short TYPVAL::GetTypedValue(PSZ s) {return (short)atoi(s);} +template <> longlong TYPVAL::GetTypedValue(PSZ s) {return atoll(s);} +template <> double TYPVAL::GetTypedValue(PSZ s) {return atof(s);} @@ -630,15 +640,19 @@ void TYPVAL::SetValue_pvblk(PVBLK blk, int n) Null = false; } // end of SetValue +template <> int TYPVAL::GetTypedValue(PVBLK blk, int n) {return blk->GetIntValue(n);} +template <> short TYPVAL::GetTypedValue(PVBLK blk, int n) {return blk->GetShortValue(n);} +template <> longlong TYPVAL::GetTypedValue(PVBLK blk, int n) {return blk->GetBigintValue(n);} +template <> double TYPVAL::GetTypedValue(PVBLK blk, int n) {return blk->GetFloatValue(n);} @@ -687,6 +701,7 @@ char *TYPVAL::ShowValue(char *buf, int len) return buf; } // end of ShowValue +template <> char *TYPVAL::ShowValue(char *buf, int len) { // TODO: use snprintf to avoid possible overflow @@ -704,6 +719,7 @@ char *TYPVAL::GetCharString(char *p) return p; } // end of GetCharString +template <> char *TYPVAL::GetCharString(char *p) { sprintf(p, Fmt, Prec, Tval); @@ -834,9 +850,9 @@ void TYPVAL::Print(PGLOBAL g, char *ps, uint z) TYPVAL::TYPVAL(PSZ s) : VALUE(TYPE_STRING) { Strp = s; - Len = strlen(s); - Clen = Len; - Ci = false; + Len = strlen(s); + Clen = Len; + Ci = false; } // end of STRING constructor /***********************************************************************/ @@ -858,27 +874,27 @@ TYPVAL::TYPVAL(PGLOBAL g, PSZ s, int n, int c) Ci = (c != 0); } // end of STRING constructor -/***********************************************************************/ -/* STRING SetValue: copy the value of another Value object. */ -/***********************************************************************/ -bool TYPVAL::SetValue_pval(PVAL valp, bool chktype) - { - if (chktype && (valp->GetType() != Type || valp->GetSize() > Len)) - return true; - - char buf[32]; - - if (!(Null = valp->IsNull() && Nullable)) - strncpy(Strp, valp->GetCharString(buf), Len); - else - Reset(); - - return false; - } // end of SetValue_pval - -/***********************************************************************/ -/* STRING SetValue: fill string with chars extracted from a line. */ -/***********************************************************************/ +/***********************************************************************/ +/* STRING SetValue: copy the value of another Value object. */ +/***********************************************************************/ +bool TYPVAL::SetValue_pval(PVAL valp, bool chktype) + { + if (chktype && (valp->GetType() != Type || valp->GetSize() > Len)) + return true; + + char buf[32]; + + if (!(Null = valp->IsNull() && Nullable)) + strncpy(Strp, valp->GetCharString(buf), Len); + else + Reset(); + + return false; + } // end of SetValue_pval + +/***********************************************************************/ +/* STRING SetValue: fill string with chars extracted from a line. */ +/***********************************************************************/ void TYPVAL::SetValue_char(char *p, int n) { n = min(n, Len); @@ -894,23 +910,23 @@ void TYPVAL::SetValue_char(char *p, int n) Null = false; } // end of SetValue_char -/***********************************************************************/ -/* STRING SetValue: fill string with another string. */ -/***********************************************************************/ -void TYPVAL::SetValue_psz(PSZ s) - { - strncpy(Strp, s, Len); - Null = false; - } // end of SetValue_psz - -/***********************************************************************/ -/* STRING SetValue: fill string with a string extracted from a block. */ -/***********************************************************************/ -void TYPVAL::SetValue_pvblk(PVBLK blk, int n) - { - strncpy(Strp, blk->GetCharValue(n), Len); - } // end of SetValue_pvblk - +/***********************************************************************/ +/* STRING SetValue: fill string with another string. */ +/***********************************************************************/ +void TYPVAL::SetValue_psz(PSZ s) + { + strncpy(Strp, s, Len); + Null = false; + } // end of SetValue_psz + +/***********************************************************************/ +/* STRING SetValue: fill string with a string extracted from a block. */ +/***********************************************************************/ +void TYPVAL::SetValue_pvblk(PVBLK blk, int n) + { + strncpy(Strp, blk->GetCharValue(n), Len); + } // end of SetValue_pvblk + /***********************************************************************/ /* STRING SetValue: get the character representation of an integer. */ /***********************************************************************/ @@ -981,21 +997,21 @@ void TYPVAL::SetValue(double f) Null = false; } // end of SetValue -/***********************************************************************/ -/* STRING SetBinValue: fill string with chars extracted from a line. */ -/***********************************************************************/ +/***********************************************************************/ +/* STRING SetBinValue: fill string with chars extracted from a line. */ +/***********************************************************************/ void TYPVAL::SetBinValue(void *p) { SetValue_char((char *)p, Len); Null = false; } // end of SetBinValue -/***********************************************************************/ -/* GetBinValue: fill a buffer with the internal binary value. */ -/* This function checks whether the buffer length is enough and */ -/* returns true if not. Actual filling occurs only if go is true. */ -/* Currently used by WriteColumn of binary files. */ -/***********************************************************************/ +/***********************************************************************/ +/* GetBinValue: fill a buffer with the internal binary value. */ +/* This function checks whether the buffer length is enough and */ +/* returns true if not. Actual filling occurs only if go is true. */ +/* Currently used by WriteColumn of binary files. */ +/***********************************************************************/ bool TYPVAL::GetBinValue(void *buf, int buflen, bool go) { int len = (Null) ? 0 : strlen(Strp); @@ -1010,92 +1026,92 @@ bool TYPVAL::GetBinValue(void *buf, int buflen, bool go) return false; } // end of GetBinValue -/***********************************************************************/ -/* STRING ShowValue: get string representation of a char value. */ -/***********************************************************************/ +/***********************************************************************/ +/* STRING ShowValue: get string representation of a char value. */ +/***********************************************************************/ char *TYPVAL::ShowValue(char *buf, int len) { return Strp; } // end of ShowValue -/***********************************************************************/ -/* STRING GetCharString: get string representation of a char value. */ -/***********************************************************************/ +/***********************************************************************/ +/* STRING GetCharString: get string representation of a char value. */ +/***********************************************************************/ char *TYPVAL::GetCharString(char *p) { return Strp; } // end of GetCharString -/***********************************************************************/ -/* STRING GetShortString: get short representation of a char value. */ -/***********************************************************************/ -char *TYPVAL::GetShortString(char *p, int n) +/***********************************************************************/ +/* STRING GetShortString: get short representation of a char value. */ +/***********************************************************************/ +char *TYPVAL::GetShortString(char *p, int n) { sprintf(p, "%*hd", n, (short)(Null ? 0 : atoi(Strp))); return p; } // end of GetShortString -/***********************************************************************/ -/* STRING GetIntString: get int representation of a char value. */ -/***********************************************************************/ -char *TYPVAL::GetIntString(char *p, int n) - { - sprintf(p, "%*ld", n, (Null) ? 0 : atol(Strp)); - return p; - } // end of GetIntString +/***********************************************************************/ +/* STRING GetIntString: get int representation of a char value. */ +/***********************************************************************/ +char *TYPVAL::GetIntString(char *p, int n) + { + sprintf(p, "%*ld", n, (Null) ? 0 : atol(Strp)); + return p; + } // end of GetIntString -/***********************************************************************/ -/* STRING GetBigintString: get big int representation of a char value.*/ -/***********************************************************************/ -char *TYPVAL::GetBigintString(char *p, int n) - { - sprintf(p, "%*lld", n, (Null) ? 0 : atoll(Strp)); - return p; - } // end of GetBigintString - -/***********************************************************************/ -/* STRING GetFloatString: get double representation of a char value. */ -/***********************************************************************/ -char *TYPVAL::GetFloatString(char *p, int n, int prec) - { - sprintf(p, "%*.*lf", n, (prec < 0) ? 2 : prec, Null ? 0 : atof(Strp)); - return p; - } // end of GetFloatString - -/***********************************************************************/ -/* STRING compare value with another Value. */ -/***********************************************************************/ -bool TYPVAL::IsEqual(PVAL vp, bool chktype) - { - if (this == vp) - return true; - else if (chktype && Type != vp->GetType()) - return false; - else if (Null || vp->IsNull()) - return false; - else if (Ci || vp->IsCi()) - return !stricmp(Strp, vp->GetCharValue()); - else // (!Ci) - return !strcmp(Strp, vp->GetCharValue()); - - } // end of IsEqual - -/***********************************************************************/ -/* FormatValue: This function set vp (a STRING value) to the string */ -/* constructed from its own value formated using the fmt format. */ -/* This function assumes that the format matches the value type. */ -/***********************************************************************/ -bool TYPVAL::FormatValue(PVAL vp, char *fmt) - { - char *buf = (char*)vp->GetTo_Val(); // Should be big enough - int n = sprintf(buf, fmt, Strp); - - return (n > vp->GetValLen()); - } // end of FormatValue - -/***********************************************************************/ -/* STRING SetFormat function (used to set SELECT output format). */ -/***********************************************************************/ +/***********************************************************************/ +/* STRING GetBigintString: get big int representation of a char value.*/ +/***********************************************************************/ +char *TYPVAL::GetBigintString(char *p, int n) + { + sprintf(p, "%*lld", n, (Null) ? 0 : atoll(Strp)); + return p; + } // end of GetBigintString + +/***********************************************************************/ +/* STRING GetFloatString: get double representation of a char value. */ +/***********************************************************************/ +char *TYPVAL::GetFloatString(char *p, int n, int prec) + { + sprintf(p, "%*.*lf", n, (prec < 0) ? 2 : prec, Null ? 0 : atof(Strp)); + return p; + } // end of GetFloatString + +/***********************************************************************/ +/* STRING compare value with another Value. */ +/***********************************************************************/ +bool TYPVAL::IsEqual(PVAL vp, bool chktype) + { + if (this == vp) + return true; + else if (chktype && Type != vp->GetType()) + return false; + else if (Null || vp->IsNull()) + return false; + else if (Ci || vp->IsCi()) + return !stricmp(Strp, vp->GetCharValue()); + else // (!Ci) + return !strcmp(Strp, vp->GetCharValue()); + + } // end of IsEqual + +/***********************************************************************/ +/* FormatValue: This function set vp (a STRING value) to the string */ +/* constructed from its own value formated using the fmt format. */ +/* This function assumes that the format matches the value type. */ +/***********************************************************************/ +bool TYPVAL::FormatValue(PVAL vp, char *fmt) + { + char *buf = (char*)vp->GetTo_Val(); // Should be big enough + int n = sprintf(buf, fmt, Strp); + + return (n > vp->GetValLen()); + } // end of FormatValue + +/***********************************************************************/ +/* STRING SetFormat function (used to set SELECT output format). */ +/***********************************************************************/ bool TYPVAL::SetConstFormat(PGLOBAL g, FORMAT& fmt) { fmt.Type[0] = 'C'; @@ -1173,7 +1189,7 @@ bool DTVAL::SetFormat(PGLOBAL g, PVAL valp) /***********************************************************************/ void DTVAL::SetTimeShift(void) { - struct tm dtm = {0,0,0,2,0,70,0,0,0}; + struct tm dtm = {0,0,0,2,0,70,0,0,0,0,0}; Shift = (int)mktime(&dtm) - 86400; @@ -1257,7 +1273,7 @@ bool DTVAL::MakeDate(PGLOBAL g, int *val, int nval) int i, m; int n; bool rc = false; - struct tm datm = {0,0,0,1,0,70,0,0,0}; + struct tm datm = {0,0,0,1,0,70,0,0,0,0,0}; if (trace) htrc("MakeDate from(%d,%d,%d,%d,%d,%d) nval=%d\n",