1
- /* $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/informix.c,v 1.42 2006/04/24 09:45:22 meskes Exp $ */
1
+ /* $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/informix.c,v 1.43 2006/06/21 10:24:40 meskes Exp $ */
2
2
3
3
#include <stdlib.h>
4
4
#include <string.h>
@@ -211,13 +211,14 @@ deccvasc(char *cp, int len, decimal *np)
211
211
int
212
212
deccvdbl (double dbl , decimal * np )
213
213
{
214
- numeric * nres = PGTYPESnumeric_new () ;
214
+ numeric * nres ;
215
215
int result = 1 ;
216
216
217
217
rsetnull (CDECIMALTYPE , (char * ) np );
218
218
if (risnull (CDOUBLETYPE , (char * ) & dbl ))
219
219
return 0 ;
220
220
221
+ nres = PGTYPESnumeric_new ();
221
222
if (nres == NULL )
222
223
return ECPG_INFORMIX_OUT_OF_MEMORY ;
223
224
@@ -232,13 +233,14 @@ deccvdbl(double dbl, decimal *np)
232
233
int
233
234
deccvint (int in , decimal * np )
234
235
{
235
- numeric * nres = PGTYPESnumeric_new () ;
236
+ numeric * nres ;
236
237
int result = 1 ;
237
238
238
239
rsetnull (CDECIMALTYPE , (char * ) np );
239
240
if (risnull (CINTTYPE , (char * ) & in ))
240
241
return 0 ;
241
242
243
+ nres = PGTYPESnumeric_new ();
242
244
if (nres == NULL )
243
245
return ECPG_INFORMIX_OUT_OF_MEMORY ;
244
246
@@ -253,13 +255,14 @@ deccvint(int in, decimal *np)
253
255
int
254
256
deccvlong (long lng , decimal * np )
255
257
{
256
- numeric * nres = PGTYPESnumeric_new () ;
258
+ numeric * nres ;
257
259
int result = 1 ;
258
260
259
261
rsetnull (CDECIMALTYPE , (char * ) np );
260
262
if (risnull (CLONGTYPE , (char * ) & lng ))
261
263
return 0 ;
262
264
265
+ nres = PGTYPESnumeric_new ();
263
266
if (nres == NULL )
264
267
return ECPG_INFORMIX_OUT_OF_MEMORY ;
265
268
@@ -342,17 +345,21 @@ int
342
345
dectoasc (decimal * np , char * cp , int len , int right )
343
346
{
344
347
char * str ;
345
- numeric * nres = PGTYPESnumeric_new ();
346
-
347
- if (nres == NULL )
348
- return ECPG_INFORMIX_OUT_OF_MEMORY ;
348
+ numeric * nres ;
349
349
350
350
rsetnull (CSTRINGTYPE , (char * ) cp );
351
351
if (risnull (CDECIMALTYPE , (char * ) np ))
352
352
return 0 ;
353
353
354
+ nres = PGTYPESnumeric_new ();
355
+ if (nres == NULL )
356
+ return ECPG_INFORMIX_OUT_OF_MEMORY ;
357
+
354
358
if (PGTYPESnumeric_from_decimal (np , nres ) != 0 )
359
+ {
360
+ PGTYPESnumeric_free (nres );
355
361
return ECPG_INFORMIX_OUT_OF_MEMORY ;
362
+ }
356
363
357
364
if (right >= 0 )
358
365
str = PGTYPESnumeric_to_asc (nres , right );
@@ -376,14 +383,17 @@ dectoasc(decimal *np, char *cp, int len, int right)
376
383
int
377
384
dectodbl (decimal * np , double * dblp )
378
385
{
379
- numeric * nres = PGTYPESnumeric_new ();
380
386
int i ;
387
+ numeric * nres = PGTYPESnumeric_new ();
381
388
382
389
if (nres == NULL )
383
390
return ECPG_INFORMIX_OUT_OF_MEMORY ;
384
391
385
392
if (PGTYPESnumeric_from_decimal (np , nres ) != 0 )
393
+ {
394
+ PGTYPESnumeric_free (nres );
386
395
return ECPG_INFORMIX_OUT_OF_MEMORY ;
396
+ }
387
397
388
398
i = PGTYPESnumeric_to_double (nres , dblp );
389
399
PGTYPESnumeric_free (nres );
@@ -401,7 +411,10 @@ dectoint(decimal *np, int *ip)
401
411
return ECPG_INFORMIX_OUT_OF_MEMORY ;
402
412
403
413
if (PGTYPESnumeric_from_decimal (np , nres ) != 0 )
414
+ {
415
+ PGTYPESnumeric_free (nres );
404
416
return ECPG_INFORMIX_OUT_OF_MEMORY ;
417
+ }
405
418
406
419
ret = PGTYPESnumeric_to_int (nres , ip );
407
420
@@ -415,15 +428,19 @@ int
415
428
dectolong (decimal * np , long * lngp )
416
429
{
417
430
int ret ;
418
- numeric * nres = PGTYPESnumeric_new ();;
431
+ numeric * nres = PGTYPESnumeric_new ();
419
432
420
433
if (nres == NULL )
421
434
return ECPG_INFORMIX_OUT_OF_MEMORY ;
422
435
423
436
if (PGTYPESnumeric_from_decimal (np , nres ) != 0 )
437
+ {
438
+ PGTYPESnumeric_free (nres );
424
439
return ECPG_INFORMIX_OUT_OF_MEMORY ;
440
+ }
425
441
426
442
ret = PGTYPESnumeric_to_long (nres , lngp );
443
+ PGTYPESnumeric_free (nres );
427
444
428
445
if (ret == PGTYPES_NUM_OVERFLOW )
429
446
ret = ECPG_INFORMIX_NUM_OVERFLOW ;
0 commit comments