Date: Monday, December 4, 2006 @ 15:06:07
Author: gilles
Path: /cvsroot/carob/carob/src
Modified: BigDecimal.cpp (1.30 -> 1.31)
Memory leak fixes by cleaning up data before throwing exceptions
----------------+
BigDecimal.cpp | 15 ++++++++++++++-
1 files changed, 14 insertions(+), 1 deletion(-)
Index: carob/src/BigDecimal.cpp
diff -u carob/src/BigDecimal.cpp:1.30 carob/src/BigDecimal.cpp:1.31
--- carob/src/BigDecimal.cpp:1.30 Thu Oct 19 17:54:17 2006
+++ carob/src/BigDecimal.cpp Mon Dec 4 15:06:07 2006
@@ -399,8 +399,11 @@
if (signum>0)
{
if (!mpz_fits_sint_p(scaled_int))
+ {
+ mpz_clear(scaled_int);
throw (ConversionException(L"BigDecimal " + static_cast<wstring>(*this)
+ L" is to big to be converted into an int", CONV_NUM_RANGE));
+ }
}
else
{
@@ -408,14 +411,19 @@
mpz_t tmp; mpz_init(tmp);
mpz_neg(tmp, scaled_int);
if (!mpz_fits_sint_p(tmp))
+ {
+ mpz_clear(tmp);
+ mpz_clear(scaled_int);
throw (ConversionException(L"BigDecimal " + static_cast<wstring>(*this)
+ L" is to big to be converted into an int", CONV_NUM_RANGE));
+ }
mpz_clear(tmp);
}
int mag_length = -1;
int* mag = toIntArray(scaled_int, &mag_length);
if (mag_length <= 0)
{
+ mpz_clear(scaled_int);
throw (ConversionException(L"BigDecimal " + static_cast<wstring>(*this)
+ L" could not be converted to int", L"FIXME"));
}
@@ -460,6 +468,7 @@
}
if (numTooBig)
{
+ mpz_clear(scaled_int);
throw (ConversionException(L"BigDecimal " + static_cast<wstring>(*this)
+ L" is too big to be converted into an int64_t", CONV_NUM_RANGE));
}
@@ -468,6 +477,7 @@
int* mag = toIntArray(scaled_int, &mag_length);
if (mag_length <= 0) //should not happen, but safer
{
+ mpz_clear(scaled_int);
throw (ConversionException(L"BigDecimal " + static_cast<wstring>(*this)
+ L" could not be converted to int64", L"FIXME"));
}
@@ -504,13 +514,16 @@
// check size
size_t nbBitsNeeded = mpz_sizeinbase(scaled_int, 2);
if (nbBitsNeeded > (sizeof(int64_t)*8))
+ {
+ mpz_clear(scaled_int);
throw (ConversionException(L"BigDecimal " + static_cast<wstring>(*this)
+ L" is too big to be converted into an int64_t", CONV_NUM_RANGE));
-
+ }
int mag_length = -1;
int* mag = toIntArray(scaled_int, &mag_length);
if (mag_length <= 0) //should not happen, but safer
{
+ mpz_clear(scaled_int);
throw (ConversionException(L"BigDecimal " + static_cast<wstring>(*this)
+ L" could not be converted to int64", L"FIXME"));
}
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits