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)
} // endif
free(dup);
free(g->Activityp);
g= NULL;
} // endif g
......
......@@ -508,6 +508,7 @@ int TYPVAL<TYPE>::GetValLen(void)
return sprintf(c, Fmt, Tval);
} // end of GetValLen
template <>
int TYPVAL<double>::GetValLen(void)
{
char c[32];
......@@ -534,15 +535,19 @@ bool TYPVAL<TYPE>::SetValue_pval(PVAL valp, bool chktype)
return false;
} // end of SetValue
template <>
short TYPVAL<short>::GetTypedValue(PVAL valp)
{return valp->GetShortValue();}
template <>
int TYPVAL<int>::GetTypedValue(PVAL valp)
{return valp->GetIntValue();}
template <>
longlong TYPVAL<longlong>::GetTypedValue(PVAL valp)
{return valp->GetBigintValue();}
template <>
double TYPVAL<double>::GetTypedValue(PVAL valp)
{return valp->GetFloatValue();}
......@@ -587,6 +592,7 @@ void TYPVAL<TYPE>::SetValue_char(char *p, int n)
Null = false;
} // end of SetValue
template <>
void TYPVAL<double>::SetValue_char(char *p, int n)
{
char *p2, buf[32];
......@@ -614,9 +620,13 @@ void TYPVAL<TYPE>::SetValue_psz(PSZ s)
Null = false;
} // end of SetValue
template <>
int TYPVAL<int>::GetTypedValue(PSZ s) {return atol(s);}
template <>
short TYPVAL<short>::GetTypedValue(PSZ s) {return (short)atoi(s);}
template <>
longlong TYPVAL<longlong>::GetTypedValue(PSZ s) {return atoll(s);}
template <>
double TYPVAL<double>::GetTypedValue(PSZ s) {return atof(s);}
......@@ -630,15 +640,19 @@ void TYPVAL<TYPE>::SetValue_pvblk(PVBLK blk, int n)
Null = false;
} // end of SetValue
template <>
int TYPVAL<int>::GetTypedValue(PVBLK blk, int n)
{return blk->GetIntValue(n);}
template <>
short TYPVAL<short>::GetTypedValue(PVBLK blk, int n)
{return blk->GetShortValue(n);}
template <>
longlong TYPVAL<longlong>::GetTypedValue(PVBLK blk, int n)
{return blk->GetBigintValue(n);}
template <>
double TYPVAL<double>::GetTypedValue(PVBLK blk, int n)
{return blk->GetFloatValue(n);}
......@@ -687,6 +701,7 @@ char *TYPVAL<TYPE>::ShowValue(char *buf, int len)
return buf;
} // end of ShowValue
template <>
char *TYPVAL<double>::ShowValue(char *buf, int len)
{
// TODO: use snprintf to avoid possible overflow
......@@ -704,6 +719,7 @@ char *TYPVAL<TYPE>::GetCharString(char *p)
return p;
} // end of GetCharString
template <>
char *TYPVAL<double>::GetCharString(char *p)
{
sprintf(p, Fmt, Prec, Tval);
......@@ -834,9 +850,9 @@ void TYPVAL<TYPE>::Print(PGLOBAL g, char *ps, uint z)
TYPVAL<PSZ>::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<PSZ>::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<PSZ>::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<PSZ>::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<PSZ>::SetValue_char(char *p, int n)
{
n = min(n, Len);
......@@ -894,23 +910,23 @@ void TYPVAL<PSZ>::SetValue_char(char *p, int n)
Null = false;
} // end of SetValue_char
/***********************************************************************/
/* STRING SetValue: fill string with another string. */
/***********************************************************************/
void TYPVAL<PSZ>::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<PSZ>::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<PSZ>::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<PSZ>::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<PSZ>::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<PSZ>::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<PSZ>::GetBinValue(void *buf, int buflen, bool go)
{
int len = (Null) ? 0 : strlen(Strp);
......@@ -1010,92 +1026,92 @@ bool TYPVAL<PSZ>::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<PSZ>::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<PSZ>::GetCharString(char *p)
{
return Strp;
} // end of GetCharString
/***********************************************************************/
/* STRING GetShortString: get short representation of a char value. */
/***********************************************************************/
char *TYPVAL<PSZ>::GetShortString(char *p, int n)
/***********************************************************************/
/* STRING GetShortString: get short representation of a char value. */
/***********************************************************************/
char *TYPVAL<PSZ>::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<PSZ>::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<PSZ>::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<PSZ>::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<PSZ>::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<PSZ>::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 GetIntString: get int representation of a char value. */
/***********************************************************************/
char *TYPVAL<PSZ>::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<PSZ>::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<PSZ>::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<PSZ>::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<PSZ>::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<PSZ>::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",
......
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