Skip to content

Commit a829da1

Browse files
author
Michael Meskes
committed
Added fixed from the coverity report send in by Joachim Wieland <joe@mcknight.de>
Added missing error handling in a few functions in ecpglib
1 parent 27c3e3d commit a829da1

File tree

12 files changed

+288
-119
lines changed

12 files changed

+288
-119
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2014,6 +2014,12 @@ Tu Jun 6 12:09:56 CEST 2006
20142014
Mo Jun 19 11:15:50 CEST 2006
20152015

20162016
- Do not use already free'ed errmsg, bug found by Joachim Wieland
2017-
<joachim.wieland@credativ.de>
2017+
<joe@mcknight.de>
2018+
2019+
We Jun 21 09:24:53 CEST 2006
2020+
2021+
- Added fixed from the coverity report send in by Joachim Wieland
2022+
<joe@mcknight.de>
2023+
- Added missing error handling in a few functions in ecpglib.
20182024
- Set ecpg library version to 5.2.
20192025
- Set ecpg version to 4.2.1.

src/interfaces/ecpg/compatlib/informix.c

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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 $ */
22

33
#include <stdlib.h>
44
#include <string.h>
@@ -211,13 +211,14 @@ deccvasc(char *cp, int len, decimal *np)
211211
int
212212
deccvdbl(double dbl, decimal *np)
213213
{
214-
numeric *nres = PGTYPESnumeric_new();
214+
numeric *nres;
215215
int result = 1;
216216

217217
rsetnull(CDECIMALTYPE, (char *) np);
218218
if (risnull(CDOUBLETYPE, (char *) &dbl))
219219
return 0;
220220

221+
nres = PGTYPESnumeric_new();
221222
if (nres == NULL)
222223
return ECPG_INFORMIX_OUT_OF_MEMORY;
223224

@@ -232,13 +233,14 @@ deccvdbl(double dbl, decimal *np)
232233
int
233234
deccvint(int in, decimal *np)
234235
{
235-
numeric *nres = PGTYPESnumeric_new();
236+
numeric *nres;
236237
int result = 1;
237238

238239
rsetnull(CDECIMALTYPE, (char *) np);
239240
if (risnull(CINTTYPE, (char *) &in))
240241
return 0;
241242

243+
nres = PGTYPESnumeric_new();
242244
if (nres == NULL)
243245
return ECPG_INFORMIX_OUT_OF_MEMORY;
244246

@@ -253,13 +255,14 @@ deccvint(int in, decimal *np)
253255
int
254256
deccvlong(long lng, decimal *np)
255257
{
256-
numeric *nres = PGTYPESnumeric_new();
258+
numeric *nres;
257259
int result = 1;
258260

259261
rsetnull(CDECIMALTYPE, (char *) np);
260262
if (risnull(CLONGTYPE, (char *) &lng))
261263
return 0;
262264

265+
nres = PGTYPESnumeric_new();
263266
if (nres == NULL)
264267
return ECPG_INFORMIX_OUT_OF_MEMORY;
265268

@@ -342,17 +345,21 @@ int
342345
dectoasc(decimal *np, char *cp, int len, int right)
343346
{
344347
char *str;
345-
numeric *nres = PGTYPESnumeric_new();
346-
347-
if (nres == NULL)
348-
return ECPG_INFORMIX_OUT_OF_MEMORY;
348+
numeric *nres;
349349

350350
rsetnull(CSTRINGTYPE, (char *) cp);
351351
if (risnull(CDECIMALTYPE, (char *) np))
352352
return 0;
353353

354+
nres = PGTYPESnumeric_new();
355+
if (nres == NULL)
356+
return ECPG_INFORMIX_OUT_OF_MEMORY;
357+
354358
if (PGTYPESnumeric_from_decimal(np, nres) != 0)
359+
{
360+
PGTYPESnumeric_free(nres);
355361
return ECPG_INFORMIX_OUT_OF_MEMORY;
362+
}
356363

357364
if (right >= 0)
358365
str = PGTYPESnumeric_to_asc(nres, right);
@@ -376,14 +383,17 @@ dectoasc(decimal *np, char *cp, int len, int right)
376383
int
377384
dectodbl(decimal *np, double *dblp)
378385
{
379-
numeric *nres = PGTYPESnumeric_new();
380386
int i;
387+
numeric *nres = PGTYPESnumeric_new();
381388

382389
if (nres == NULL)
383390
return ECPG_INFORMIX_OUT_OF_MEMORY;
384391

385392
if (PGTYPESnumeric_from_decimal(np, nres) != 0)
393+
{
394+
PGTYPESnumeric_free(nres);
386395
return ECPG_INFORMIX_OUT_OF_MEMORY;
396+
}
387397

388398
i = PGTYPESnumeric_to_double(nres, dblp);
389399
PGTYPESnumeric_free(nres);
@@ -401,7 +411,10 @@ dectoint(decimal *np, int *ip)
401411
return ECPG_INFORMIX_OUT_OF_MEMORY;
402412

403413
if (PGTYPESnumeric_from_decimal(np, nres) != 0)
414+
{
415+
PGTYPESnumeric_free(nres);
404416
return ECPG_INFORMIX_OUT_OF_MEMORY;
417+
}
405418

406419
ret = PGTYPESnumeric_to_int(nres, ip);
407420

@@ -415,15 +428,19 @@ int
415428
dectolong(decimal *np, long *lngp)
416429
{
417430
int ret;
418-
numeric *nres = PGTYPESnumeric_new();;
431+
numeric *nres = PGTYPESnumeric_new();
419432

420433
if (nres == NULL)
421434
return ECPG_INFORMIX_OUT_OF_MEMORY;
422435

423436
if (PGTYPESnumeric_from_decimal(np, nres) != 0)
437+
{
438+
PGTYPESnumeric_free(nres);
424439
return ECPG_INFORMIX_OUT_OF_MEMORY;
440+
}
425441

426442
ret = PGTYPESnumeric_to_long(nres, lngp);
443+
PGTYPESnumeric_free(nres);
427444

428445
if (ret == PGTYPES_NUM_OVERFLOW)
429446
ret = ECPG_INFORMIX_NUM_OVERFLOW;

src/interfaces/ecpg/ecpglib/connect.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.28 2006/06/19 09:19:49 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.29 2006/06/21 10:24:40 meskes Exp $ */
22

33
#define POSTGRES_ECPG_INTERNAL
44
#include "postgres_fe.h"
@@ -403,6 +403,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
403403
ECPGfree(realname);
404404
if (dbname)
405405
ECPGfree(dbname);
406+
ecpg_finish(this);
406407
return false;
407408
}
408409
}

0 commit comments

Comments
 (0)