Commit 0a05caf2 authored by unknown's avatar unknown

- Fix memory leak

modified:
  storage/connect/connect.cc
  
- GCC requires template<> headers

modified:
  storage/connect/value.cpp
parent bf6c3f51
...@@ -82,6 +82,7 @@ PGLOBAL CntExit(PGLOBAL g) ...@@ -82,6 +82,7 @@ PGLOBAL CntExit(PGLOBAL g)
} // endif } // endif
free(dup); free(dup);
free(g->Activityp);
g= NULL; g= NULL;
} // endif g } // endif g
......
...@@ -508,6 +508,7 @@ int TYPVAL<TYPE>::GetValLen(void) ...@@ -508,6 +508,7 @@ int TYPVAL<TYPE>::GetValLen(void)
return sprintf(c, Fmt, Tval); return sprintf(c, Fmt, Tval);
} // end of GetValLen } // end of GetValLen
template <>
int TYPVAL<double>::GetValLen(void) int TYPVAL<double>::GetValLen(void)
{ {
char c[32]; char c[32];
...@@ -534,15 +535,19 @@ bool TYPVAL<TYPE>::SetValue_pval(PVAL valp, bool chktype) ...@@ -534,15 +535,19 @@ bool TYPVAL<TYPE>::SetValue_pval(PVAL valp, bool chktype)
return false; return false;
} // end of SetValue } // end of SetValue
template <>
short TYPVAL<short>::GetTypedValue(PVAL valp) short TYPVAL<short>::GetTypedValue(PVAL valp)
{return valp->GetShortValue();} {return valp->GetShortValue();}
template <>
int TYPVAL<int>::GetTypedValue(PVAL valp) int TYPVAL<int>::GetTypedValue(PVAL valp)
{return valp->GetIntValue();} {return valp->GetIntValue();}
template <>
longlong TYPVAL<longlong>::GetTypedValue(PVAL valp) longlong TYPVAL<longlong>::GetTypedValue(PVAL valp)
{return valp->GetBigintValue();} {return valp->GetBigintValue();}
template <>
double TYPVAL<double>::GetTypedValue(PVAL valp) double TYPVAL<double>::GetTypedValue(PVAL valp)
{return valp->GetFloatValue();} {return valp->GetFloatValue();}
...@@ -587,6 +592,7 @@ void TYPVAL<TYPE>::SetValue_char(char *p, int n) ...@@ -587,6 +592,7 @@ void TYPVAL<TYPE>::SetValue_char(char *p, int n)
Null = false; Null = false;
} // end of SetValue } // end of SetValue
template <>
void TYPVAL<double>::SetValue_char(char *p, int n) void TYPVAL<double>::SetValue_char(char *p, int n)
{ {
char *p2, buf[32]; char *p2, buf[32];
...@@ -614,9 +620,13 @@ void TYPVAL<TYPE>::SetValue_psz(PSZ s) ...@@ -614,9 +620,13 @@ void TYPVAL<TYPE>::SetValue_psz(PSZ s)
Null = false; Null = false;
} // end of SetValue } // end of SetValue
template <>
int TYPVAL<int>::GetTypedValue(PSZ s) {return atol(s);} int TYPVAL<int>::GetTypedValue(PSZ s) {return atol(s);}
template <>
short TYPVAL<short>::GetTypedValue(PSZ s) {return (short)atoi(s);} short TYPVAL<short>::GetTypedValue(PSZ s) {return (short)atoi(s);}
template <>
longlong TYPVAL<longlong>::GetTypedValue(PSZ s) {return atoll(s);} longlong TYPVAL<longlong>::GetTypedValue(PSZ s) {return atoll(s);}
template <>
double TYPVAL<double>::GetTypedValue(PSZ s) {return atof(s);} double TYPVAL<double>::GetTypedValue(PSZ s) {return atof(s);}
...@@ -630,15 +640,19 @@ void TYPVAL<TYPE>::SetValue_pvblk(PVBLK blk, int n) ...@@ -630,15 +640,19 @@ void TYPVAL<TYPE>::SetValue_pvblk(PVBLK blk, int n)
Null = false; Null = false;
} // end of SetValue } // end of SetValue
template <>
int TYPVAL<int>::GetTypedValue(PVBLK blk, int n) int TYPVAL<int>::GetTypedValue(PVBLK blk, int n)
{return blk->GetIntValue(n);} {return blk->GetIntValue(n);}
template <>
short TYPVAL<short>::GetTypedValue(PVBLK blk, int n) short TYPVAL<short>::GetTypedValue(PVBLK blk, int n)
{return blk->GetShortValue(n);} {return blk->GetShortValue(n);}
template <>
longlong TYPVAL<longlong>::GetTypedValue(PVBLK blk, int n) longlong TYPVAL<longlong>::GetTypedValue(PVBLK blk, int n)
{return blk->GetBigintValue(n);} {return blk->GetBigintValue(n);}
template <>
double TYPVAL<double>::GetTypedValue(PVBLK blk, int n) double TYPVAL<double>::GetTypedValue(PVBLK blk, int n)
{return blk->GetFloatValue(n);} {return blk->GetFloatValue(n);}
...@@ -687,6 +701,7 @@ char *TYPVAL<TYPE>::ShowValue(char *buf, int len) ...@@ -687,6 +701,7 @@ char *TYPVAL<TYPE>::ShowValue(char *buf, int len)
return buf; return buf;
} // end of ShowValue } // end of ShowValue
template <>
char *TYPVAL<double>::ShowValue(char *buf, int len) char *TYPVAL<double>::ShowValue(char *buf, int len)
{ {
// TODO: use snprintf to avoid possible overflow // TODO: use snprintf to avoid possible overflow
...@@ -704,6 +719,7 @@ char *TYPVAL<TYPE>::GetCharString(char *p) ...@@ -704,6 +719,7 @@ char *TYPVAL<TYPE>::GetCharString(char *p)
return p; return p;
} // end of GetCharString } // end of GetCharString
template <>
char *TYPVAL<double>::GetCharString(char *p) char *TYPVAL<double>::GetCharString(char *p)
{ {
sprintf(p, Fmt, Prec, Tval); sprintf(p, Fmt, Prec, Tval);
...@@ -834,9 +850,9 @@ void TYPVAL<TYPE>::Print(PGLOBAL g, char *ps, uint z) ...@@ -834,9 +850,9 @@ void TYPVAL<TYPE>::Print(PGLOBAL g, char *ps, uint z)
TYPVAL<PSZ>::TYPVAL(PSZ s) : VALUE(TYPE_STRING) TYPVAL<PSZ>::TYPVAL(PSZ s) : VALUE(TYPE_STRING)
{ {
Strp = s; Strp = s;
Len = strlen(s); Len = strlen(s);
Clen = Len; Clen = Len;
Ci = false; Ci = false;
} // end of STRING constructor } // end of STRING constructor
/***********************************************************************/ /***********************************************************************/
...@@ -858,27 +874,27 @@ TYPVAL<PSZ>::TYPVAL(PGLOBAL g, PSZ s, int n, int c) ...@@ -858,27 +874,27 @@ TYPVAL<PSZ>::TYPVAL(PGLOBAL g, PSZ s, int n, int c)
Ci = (c != 0); Ci = (c != 0);
} // end of STRING constructor } // end of STRING constructor
/***********************************************************************/ /***********************************************************************/
/* STRING SetValue: copy the value of another Value object. */ /* STRING SetValue: copy the value of another Value object. */
/***********************************************************************/ /***********************************************************************/
bool TYPVAL<PSZ>::SetValue_pval(PVAL valp, bool chktype) bool TYPVAL<PSZ>::SetValue_pval(PVAL valp, bool chktype)
{ {
if (chktype && (valp->GetType() != Type || valp->GetSize() > Len)) if (chktype && (valp->GetType() != Type || valp->GetSize() > Len))
return true; return true;
char buf[32]; char buf[32];
if (!(Null = valp->IsNull() && Nullable)) if (!(Null = valp->IsNull() && Nullable))
strncpy(Strp, valp->GetCharString(buf), Len); strncpy(Strp, valp->GetCharString(buf), Len);
else else
Reset(); Reset();
return false; return false;
} // end of SetValue_pval } // end of SetValue_pval
/***********************************************************************/ /***********************************************************************/
/* STRING SetValue: fill string with chars extracted from a line. */ /* STRING SetValue: fill string with chars extracted from a line. */
/***********************************************************************/ /***********************************************************************/
void TYPVAL<PSZ>::SetValue_char(char *p, int n) void TYPVAL<PSZ>::SetValue_char(char *p, int n)
{ {
n = min(n, Len); n = min(n, Len);
...@@ -894,23 +910,23 @@ void TYPVAL<PSZ>::SetValue_char(char *p, int n) ...@@ -894,23 +910,23 @@ void TYPVAL<PSZ>::SetValue_char(char *p, int n)
Null = false; Null = false;
} // end of SetValue_char } // end of SetValue_char
/***********************************************************************/ /***********************************************************************/
/* STRING SetValue: fill string with another string. */ /* STRING SetValue: fill string with another string. */
/***********************************************************************/ /***********************************************************************/
void TYPVAL<PSZ>::SetValue_psz(PSZ s) void TYPVAL<PSZ>::SetValue_psz(PSZ s)
{ {
strncpy(Strp, s, Len); strncpy(Strp, s, Len);
Null = false; Null = false;
} // end of SetValue_psz } // end of SetValue_psz
/***********************************************************************/ /***********************************************************************/
/* STRING SetValue: fill string with a string extracted from a block. */ /* STRING SetValue: fill string with a string extracted from a block. */
/***********************************************************************/ /***********************************************************************/
void TYPVAL<PSZ>::SetValue_pvblk(PVBLK blk, int n) void TYPVAL<PSZ>::SetValue_pvblk(PVBLK blk, int n)
{ {
strncpy(Strp, blk->GetCharValue(n), Len); strncpy(Strp, blk->GetCharValue(n), Len);
} // end of SetValue_pvblk } // end of SetValue_pvblk
/***********************************************************************/ /***********************************************************************/
/* STRING SetValue: get the character representation of an integer. */ /* STRING SetValue: get the character representation of an integer. */
/***********************************************************************/ /***********************************************************************/
...@@ -981,21 +997,21 @@ void TYPVAL<PSZ>::SetValue(double f) ...@@ -981,21 +997,21 @@ void TYPVAL<PSZ>::SetValue(double f)
Null = false; Null = false;
} // end of SetValue } // 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<PSZ>::SetBinValue(void *p) void TYPVAL<PSZ>::SetBinValue(void *p)
{ {
SetValue_char((char *)p, Len); SetValue_char((char *)p, Len);
Null = false; Null = false;
} // end of SetBinValue } // end of SetBinValue
/***********************************************************************/ /***********************************************************************/
/* GetBinValue: fill a buffer with the internal binary value. */ /* GetBinValue: fill a buffer with the internal binary value. */
/* This function checks whether the buffer length is enough and */ /* This function checks whether the buffer length is enough and */
/* returns true if not. Actual filling occurs only if go is true. */ /* returns true if not. Actual filling occurs only if go is true. */
/* Currently used by WriteColumn of binary files. */ /* Currently used by WriteColumn of binary files. */
/***********************************************************************/ /***********************************************************************/
bool TYPVAL<PSZ>::GetBinValue(void *buf, int buflen, bool go) bool TYPVAL<PSZ>::GetBinValue(void *buf, int buflen, bool go)
{ {
int len = (Null) ? 0 : strlen(Strp); int len = (Null) ? 0 : strlen(Strp);
...@@ -1010,92 +1026,92 @@ bool TYPVAL<PSZ>::GetBinValue(void *buf, int buflen, bool go) ...@@ -1010,92 +1026,92 @@ bool TYPVAL<PSZ>::GetBinValue(void *buf, int buflen, bool go)
return false; return false;
} // end of GetBinValue } // end of GetBinValue
/***********************************************************************/ /***********************************************************************/
/* STRING ShowValue: get string representation of a char value. */ /* STRING ShowValue: get string representation of a char value. */
/***********************************************************************/ /***********************************************************************/
char *TYPVAL<PSZ>::ShowValue(char *buf, int len) char *TYPVAL<PSZ>::ShowValue(char *buf, int len)
{ {
return Strp; return Strp;
} // end of ShowValue } // end of ShowValue
/***********************************************************************/ /***********************************************************************/
/* STRING GetCharString: get string representation of a char value. */ /* STRING GetCharString: get string representation of a char value. */
/***********************************************************************/ /***********************************************************************/
char *TYPVAL<PSZ>::GetCharString(char *p) char *TYPVAL<PSZ>::GetCharString(char *p)
{ {
return Strp; return Strp;
} // end of GetCharString } // end of GetCharString
/***********************************************************************/ /***********************************************************************/
/* STRING GetShortString: get short representation of a char value. */ /* STRING GetShortString: get short representation of a char value. */
/***********************************************************************/ /***********************************************************************/
char *TYPVAL<PSZ>::GetShortString(char *p, int n) char *TYPVAL<PSZ>::GetShortString(char *p, int n)
{ {
sprintf(p, "%*hd", n, (short)(Null ? 0 : atoi(Strp))); sprintf(p, "%*hd", n, (short)(Null ? 0 : atoi(Strp)));
return p; return p;
} // end of GetShortString } // end of GetShortString
/***********************************************************************/ /***********************************************************************/
/* STRING GetIntString: get int representation of a char value. */ /* STRING GetIntString: get int representation of a char value. */
/***********************************************************************/ /***********************************************************************/
char *TYPVAL<PSZ>::GetIntString(char *p, int n) char *TYPVAL<PSZ>::GetIntString(char *p, int n)
{ {
sprintf(p, "%*ld", n, (Null) ? 0 : atol(Strp)); sprintf(p, "%*ld", n, (Null) ? 0 : atol(Strp));
return p; return p;
} // end of GetIntString } // end of GetIntString
/***********************************************************************/ /***********************************************************************/
/* STRING GetBigintString: get big int representation of a char value.*/ /* STRING GetBigintString: get big int representation of a char value.*/
/***********************************************************************/ /***********************************************************************/
char *TYPVAL<PSZ>::GetBigintString(char *p, int n) char *TYPVAL<PSZ>::GetBigintString(char *p, int n)
{ {
sprintf(p, "%*lld", n, (Null) ? 0 : atoll(Strp)); sprintf(p, "%*lld", n, (Null) ? 0 : atoll(Strp));
return p; return p;
} // end of GetBigintString } // end of GetBigintString
/***********************************************************************/ /***********************************************************************/
/* STRING GetFloatString: get double representation of a char value. */ /* STRING GetFloatString: get double representation of a char value. */
/***********************************************************************/ /***********************************************************************/
char *TYPVAL<PSZ>::GetFloatString(char *p, int n, int prec) char *TYPVAL<PSZ>::GetFloatString(char *p, int n, int prec)
{ {
sprintf(p, "%*.*lf", n, (prec < 0) ? 2 : prec, Null ? 0 : atof(Strp)); sprintf(p, "%*.*lf", n, (prec < 0) ? 2 : prec, Null ? 0 : atof(Strp));
return p; return p;
} // end of GetFloatString } // end of GetFloatString
/***********************************************************************/ /***********************************************************************/
/* STRING compare value with another Value. */ /* STRING compare value with another Value. */
/***********************************************************************/ /***********************************************************************/
bool TYPVAL<PSZ>::IsEqual(PVAL vp, bool chktype) bool TYPVAL<PSZ>::IsEqual(PVAL vp, bool chktype)
{ {
if (this == vp) if (this == vp)
return true; return true;
else if (chktype && Type != vp->GetType()) else if (chktype && Type != vp->GetType())
return false; return false;
else if (Null || vp->IsNull()) else if (Null || vp->IsNull())
return false; return false;
else if (Ci || vp->IsCi()) else if (Ci || vp->IsCi())
return !stricmp(Strp, vp->GetCharValue()); return !stricmp(Strp, vp->GetCharValue());
else // (!Ci) else // (!Ci)
return !strcmp(Strp, vp->GetCharValue()); return !strcmp(Strp, vp->GetCharValue());
} // end of IsEqual } // end of IsEqual
/***********************************************************************/ /***********************************************************************/
/* FormatValue: This function set vp (a STRING value) to the string */ /* FormatValue: This function set vp (a STRING value) to the string */
/* constructed from its own value formated using the fmt format. */ /* constructed from its own value formated using the fmt format. */
/* This function assumes that the format matches the value type. */ /* This function assumes that the format matches the value type. */
/***********************************************************************/ /***********************************************************************/
bool TYPVAL<PSZ>::FormatValue(PVAL vp, char *fmt) bool TYPVAL<PSZ>::FormatValue(PVAL vp, char *fmt)
{ {
char *buf = (char*)vp->GetTo_Val(); // Should be big enough char *buf = (char*)vp->GetTo_Val(); // Should be big enough
int n = sprintf(buf, fmt, Strp); int n = sprintf(buf, fmt, Strp);
return (n > vp->GetValLen()); return (n > vp->GetValLen());
} // end of FormatValue } // end of FormatValue
/***********************************************************************/ /***********************************************************************/
/* STRING SetFormat function (used to set SELECT output format). */ /* STRING SetFormat function (used to set SELECT output format). */
/***********************************************************************/ /***********************************************************************/
bool TYPVAL<PSZ>::SetConstFormat(PGLOBAL g, FORMAT& fmt) bool TYPVAL<PSZ>::SetConstFormat(PGLOBAL g, FORMAT& fmt)
{ {
fmt.Type[0] = 'C'; fmt.Type[0] = 'C';
...@@ -1173,7 +1189,7 @@ bool DTVAL::SetFormat(PGLOBAL g, PVAL valp) ...@@ -1173,7 +1189,7 @@ bool DTVAL::SetFormat(PGLOBAL g, PVAL valp)
/***********************************************************************/ /***********************************************************************/
void DTVAL::SetTimeShift(void) 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; Shift = (int)mktime(&dtm) - 86400;
...@@ -1257,7 +1273,7 @@ bool DTVAL::MakeDate(PGLOBAL g, int *val, int nval) ...@@ -1257,7 +1273,7 @@ bool DTVAL::MakeDate(PGLOBAL g, int *val, int nval)
int i, m; int i, m;
int n; int n;
bool rc = false; 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) if (trace)
htrc("MakeDate from(%d,%d,%d,%d,%d,%d) nval=%d\n", htrc("MakeDate from(%d,%d,%d,%d,%d,%d) nval=%d\n",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment