Skip to content

Commit e6e61af

Browse files
author
Michael Meskes
committed
Fixed some memory bugs that somehow reappeared.
Also fixed a new Coverity report.
1 parent 7c9e2c7 commit e6e61af

File tree

9 files changed

+499
-482
lines changed

9 files changed

+499
-482
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,5 +2080,7 @@ Tu Aug 8 13:26:25 CEST 2006
20802080
We Aug 9 09:28:56 CEST 2006
20812081

20822082
- Fixed error handling in numeric conversion (Joachim).
2083+
- Fixed some memory bugs that somehow reappeared.
2084+
- Also fixed a new Coverity report.
20832085
- Set ecpg library version to 5.2.
20842086
- Set ecpg version to 4.2.1.

src/interfaces/ecpg/ecpglib/execute.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.57 2006/08/08 15:30:39 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.58 2006/08/09 09:08:31 meskes Exp $ */
22

33
/*
44
* The aim is to get a simpler inteface to the database routines.
@@ -1018,6 +1018,7 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
10181018
strcpy(mallocedval + strlen(mallocedval), "date ");
10191019
strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
10201020
strcpy(mallocedval + strlen(mallocedval), ",");
1021+
ECPGfree(str);
10211022
}
10221023
strcpy(mallocedval + strlen(mallocedval) - 1, "]");
10231024
}
@@ -1037,11 +1038,11 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
10371038
strcpy(mallocedval, "date ");
10381039
/* also copy trailing '\0' */
10391040
strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
1041+
ECPGfree(str);
10401042
}
10411043

10421044
*tobeinserted_p = mallocedval;
10431045
*malloced_p = true;
1044-
ECPGfree(str);
10451046
}
10461047
break;
10471048

@@ -1072,6 +1073,7 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
10721073
strcpy(mallocedval + strlen(mallocedval), "timestamp ");
10731074
strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
10741075
strcpy(mallocedval + strlen(mallocedval), ",");
1076+
ECPGfree(str);
10751077
}
10761078
strcpy(mallocedval + strlen(mallocedval) - 1, "]");
10771079
}
@@ -1091,11 +1093,11 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
10911093
strcpy(mallocedval, "timestamp ");
10921094
/* also copy trailing '\0' */
10931095
strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
1096+
ECPGfree(str);
10941097
}
10951098

10961099
*tobeinserted_p = mallocedval;
10971100
*malloced_p = true;
1098-
ECPGfree(str);
10991101
}
11001102
break;
11011103

src/interfaces/ecpg/pgtypeslib/numeric.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/numeric.c,v 1.29 2006/08/09 07:30:56 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/numeric.c,v 1.30 2006/08/09 09:08:31 meskes Exp $ */
22

33
#include "postgres_fe.h"
44
#include <ctype.h>
@@ -405,7 +405,10 @@ PGTYPESnumeric_to_asc(numeric *num, int dscale)
405405
dscale = num->dscale;
406406

407407
if (PGTYPESnumeric_copy(num, numcopy) < 0)
408+
{
409+
PGTYPESnumeric_free(numcopy);
408410
return NULL;
411+
}
409412
/* get_str_from_var may change its argument */
410413
s = get_str_from_var(numcopy, dscale);
411414
PGTYPESnumeric_free(numcopy);
@@ -1465,15 +1468,18 @@ PGTYPESnumeric_from_double(double d, numeric *dst)
14651468
{
14661469
char buffer[100];
14671470
numeric *tmp;
1471+
int i;
14681472

14691473
if (sprintf(buffer, "%f", d) == 0)
14701474
return -1;
14711475

14721476
if ((tmp = PGTYPESnumeric_from_asc(buffer, NULL)) == NULL)
14731477
return -1;
1474-
if (PGTYPESnumeric_copy(tmp, dst) != 0)
1475-
return -1;
1478+
i = PGTYPESnumeric_copy(tmp, dst);
14761479
PGTYPESnumeric_free(tmp);
1480+
if (i != 0)
1481+
return -1;
1482+
14771483
errno = 0;
14781484
return 0;
14791485
}
@@ -1485,14 +1491,19 @@ numericvar_to_double(numeric *var, double *dp)
14851491
double val;
14861492
char *endptr;
14871493
numeric *varcopy = PGTYPESnumeric_new();
1488-
int i;
14891494

14901495
if (PGTYPESnumeric_copy(var, varcopy) < 0)
1496+
{
1497+
PGTYPESnumeric_free(varcopy);
14911498
return -1;
1492-
if ((tmp = get_str_from_var(varcopy, varcopy->dscale)) == NULL)
1493-
return -1;
1499+
}
1500+
1501+
tmp = get_str_from_var(varcopy, varcopy->dscale);
14941502
PGTYPESnumeric_free(varcopy);
14951503

1504+
if (tmp == NULL)
1505+
return -1;
1506+
14961507
/*
14971508
* strtod seems to not reset errno to 0 in case of success.
14981509
* at least on aome architectures

src/interfaces/ecpg/preproc/type.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/type.c,v 1.69 2006/07/30 16:28:58 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/type.c,v 1.70 2006/08/09 09:08:32 meskes Exp $ */
22

33
#include "postgres_fe.h"
44

@@ -286,14 +286,16 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type,
286286
mmerror(INDICATOR_NOT_SIMPLE, ET_FATAL, "Indicator for simple datatype has to be simple.\n");
287287

288288
ECPGdump_a_simple(o, name, type->type, make_str("1"), (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("1"), struct_sizeof, prefix);
289-
ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("-1"), ind_struct_sizeof, ind_prefix);
289+
if (ind_type != NULL)
290+
ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("-1"), ind_struct_sizeof, ind_prefix);
290291
break;
291292
case ECPGt_descriptor:
292293
if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
293294
mmerror(INDICATOR_NOT_SIMPLE, ET_FATAL, "Indicator for simple datatype has to be simple.\n");
294295

295296
ECPGdump_a_simple(o, name, type->type, NULL, make_str("-1"), NULL, prefix);
296-
ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, make_str("-1"), NULL, ind_prefix);
297+
if (ind_type != NULL)
298+
ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, make_str("-1"), NULL, ind_prefix);
297299
break;
298300
default:
299301
if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))

src/interfaces/ecpg/test/expected/pgtypeslib-num_test2.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ main(void)
5555
num = PGTYPESnumeric_from_asc(nums[i], &endptr);
5656
check_errno();
5757
if (endptr != NULL)
58+
{
5859
printf("endptr of %d is not NULL\n", i);
59-
if (*endptr != '\0')
60-
printf("*endptr of %d is not \\0\n", i);
60+
if (*endptr != '\0')
61+
printf("*endptr of %d is not \\0\n", i);
62+
}
6163
text = PGTYPESnumeric_to_asc(num, -1);
6264
check_errno();
6365
printf("num[%d,1]: %s\n", i, text); free(text);

src/interfaces/ecpg/test/expected/sql-dyntest.c

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ if (sqlca.sqlcode < 0) error ( );}
270270
printf("%d Columns\n",COUNT);
271271
for (INDEX=1;INDEX<=COUNT;++INDEX)
272272
{
273-
/* :NULLABLE=nullable, */{ ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_ret_octet,
273+
{ ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_ret_octet,
274274
ECPGt_int,&(RETURNED_OCTET_LENGTH),(long)1,(long)1,sizeof(int), ECPGd_name,
275275
ECPGt_char,(NAME),(long)120,(long)1,(120)*sizeof(char), ECPGd_scale,
276276
ECPGt_int,&(SCALE),(long)1,(long)1,sizeof(int), ECPGd_precision,
@@ -348,8 +348,6 @@ if (sqlca.sqlcode < 0) error ( );}
348348
else printf("<SQL3 %d> ",TYPE);
349349
break;
350350
}
351-
/* nullable is not yet implemented in ecpg */
352-
/* if (!NULLABLE) printf("not null "); */
353351
if (OCTET_LENGTH>0) printf("[%d bytes]",OCTET_LENGTH);
354352
putchar('\n');
355353
}
@@ -365,21 +363,21 @@ if (sqlca.sqlcode < 0) error ( );}
365363
ECPGt_int,&(SCALE),(long)1,(long)1,sizeof(int), ECPGd_type,
366364
ECPGt_int,&(TYPE),(long)1,(long)1,sizeof(int), ECPGd_EODT);
367365

368-
#line 138 "dyntest.pgc"
366+
#line 136 "dyntest.pgc"
369367

370368
if (sqlca.sqlcode < 0) error ( );}
371-
#line 138 "dyntest.pgc"
369+
#line 136 "dyntest.pgc"
372370

373371
if (INDICATOR==-1) printf("NULL");
374372
else switch (TYPE)
375373
{ case SQL3_BOOLEAN:
376374
{ ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
377375
ECPGt_bool,&(BOOLVAR),(long)1,(long)1,sizeof(bool), ECPGd_EODT);
378376

379-
#line 142 "dyntest.pgc"
377+
#line 140 "dyntest.pgc"
380378

381379
if (sqlca.sqlcode < 0) error ( );}
382-
#line 142 "dyntest.pgc"
380+
#line 140 "dyntest.pgc"
383381

384382
printf(BOOLVAR?"true":"false");
385383
break;
@@ -389,21 +387,21 @@ if (sqlca.sqlcode < 0) error ( );}
389387
{ { ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
390388
ECPGt_int,&(INTVAR),(long)1,(long)1,sizeof(int), ECPGd_EODT);
391389

392-
#line 148 "dyntest.pgc"
390+
#line 146 "dyntest.pgc"
393391

394392
if (sqlca.sqlcode < 0) error ( );}
395-
#line 148 "dyntest.pgc"
393+
#line 146 "dyntest.pgc"
396394

397395
printf("%*d",PRECISION,INTVAR);
398396
}
399397
else
400398
{ { ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
401399
ECPGt_float,&(FLOATVAR),(long)1,(long)1,sizeof(float), ECPGd_EODT);
402400

403-
#line 152 "dyntest.pgc"
401+
#line 150 "dyntest.pgc"
404402

405403
if (sqlca.sqlcode < 0) error ( );}
406-
#line 152 "dyntest.pgc"
404+
#line 150 "dyntest.pgc"
407405

408406
printf("%*.*f",PRECISION+1,SCALE,FLOATVAR);
409407
}
@@ -413,10 +411,10 @@ if (sqlca.sqlcode < 0) error ( );}
413411
{ ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
414412
ECPGt_int,&(INTVAR),(long)1,(long)1,sizeof(int), ECPGd_EODT);
415413

416-
#line 158 "dyntest.pgc"
414+
#line 156 "dyntest.pgc"
417415

418416
if (sqlca.sqlcode < 0) error ( );}
419-
#line 158 "dyntest.pgc"
417+
#line 156 "dyntest.pgc"
420418

421419
printf("%d",INTVAR);
422420
break;
@@ -425,21 +423,21 @@ if (sqlca.sqlcode < 0) error ( );}
425423
{ ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
426424
ECPGt_float,&(FLOATVAR),(long)1,(long)1,sizeof(float), ECPGd_EODT);
427425

428-
#line 163 "dyntest.pgc"
426+
#line 161 "dyntest.pgc"
429427

430428
if (sqlca.sqlcode < 0) error ( );}
431-
#line 163 "dyntest.pgc"
429+
#line 161 "dyntest.pgc"
432430

433431
printf("%f",FLOATVAR);
434432
break;
435433
case SQL3_DOUBLE_PRECISION:
436434
{ ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
437435
ECPGt_double,&(DOUBLEVAR),(long)1,(long)1,sizeof(double), ECPGd_EODT);
438436

439-
#line 167 "dyntest.pgc"
437+
#line 165 "dyntest.pgc"
440438

441439
if (sqlca.sqlcode < 0) error ( );}
442-
#line 167 "dyntest.pgc"
440+
#line 165 "dyntest.pgc"
443441

444442
printf("%f",DOUBLEVAR);
445443
break;
@@ -451,10 +449,10 @@ if (sqlca.sqlcode < 0) error ( );}
451449
{ ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
452450
ECPGt_char,(STRINGVAR),(long)1024,(long)1,(1024)*sizeof(char), ECPGd_EODT);
453451

454-
#line 175 "dyntest.pgc"
452+
#line 173 "dyntest.pgc"
455453

456454
if (sqlca.sqlcode < 0) error ( );}
457-
#line 175 "dyntest.pgc"
455+
#line 173 "dyntest.pgc"
458456

459457
printf("'%s'",STRINGVAR);
460458
break;
@@ -465,16 +463,16 @@ if (sqlca.sqlcode < 0) error ( );}
465463
}
466464

467465
{ ECPGdo(__LINE__, 0, 1, NULL, "close MYCURS", ECPGt_EOIT, ECPGt_EORT);
468-
#line 184 "dyntest.pgc"
466+
#line 182 "dyntest.pgc"
469467

470468
if (sqlca.sqlcode < 0) error ( );}
471-
#line 184 "dyntest.pgc"
469+
#line 182 "dyntest.pgc"
472470

473471
ECPGdeallocate_desc(__LINE__, "MYDESC");
474-
#line 185 "dyntest.pgc"
472+
#line 183 "dyntest.pgc"
475473

476474
if (sqlca.sqlcode < 0) error ( );
477-
#line 185 "dyntest.pgc"
475+
#line 183 "dyntest.pgc"
478476

479477

480478
/* no exec sql disconnect; */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy