]> granicus.if.org Git - postgresql/commitdiff
Applied Zoltan's patch to fix a few memleaks in ecpg's pgtypeslib.
authorMichael Meskes <meskes@postgresql.org>
Tue, 17 Aug 2010 09:36:05 +0000 (09:36 +0000)
committerMichael Meskes <meskes@postgresql.org>
Tue, 17 Aug 2010 09:36:05 +0000 (09:36 +0000)
18 files changed:
src/interfaces/ecpg/pgtypeslib/numeric.c
src/interfaces/ecpg/test/compat_informix/dec_test.pgc
src/interfaces/ecpg/test/expected/compat_informix-dec_test.c
src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c
src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stderr
src/interfaces/ecpg/test/expected/pgtypeslib-dt_test2.c
src/interfaces/ecpg/test/expected/pgtypeslib-nan_test.c
src/interfaces/ecpg/test/expected/pgtypeslib-nan_test.stderr
src/interfaces/ecpg/test/expected/pgtypeslib-num_test.c
src/interfaces/ecpg/test/expected/pgtypeslib-num_test.stderr
src/interfaces/ecpg/test/expected/pgtypeslib-num_test2.c
src/interfaces/ecpg/test/expected/sql-array.c
src/interfaces/ecpg/test/pgtypeslib/dt_test.pgc
src/interfaces/ecpg/test/pgtypeslib/dt_test2.pgc
src/interfaces/ecpg/test/pgtypeslib/nan_test.pgc
src/interfaces/ecpg/test/pgtypeslib/num_test.pgc
src/interfaces/ecpg/test/pgtypeslib/num_test2.pgc
src/interfaces/ecpg/test/sql/array.pgc

index 3d123489e60f7263f8579c73cf320d5d92469681..001e6cc73046bb54e77a1894d68175f4f443d446 100644 (file)
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/numeric.c,v 1.35 2010/02/02 16:09:12 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/numeric.c,v 1.36 2010/08/17 09:36:04 meskes Exp $ */
 
 #include "postgres_fe.h"
 #include <ctype.h>
@@ -417,7 +417,7 @@ PGTYPESnumeric_from_asc(char *str, char **endptr)
        ret = set_var_from_str(str, ptr, value);
        if (ret)
        {
-               free(value);
+               PGTYPESnumeric_free(value);
                return (NULL);
        }
 
@@ -1602,8 +1602,12 @@ PGTYPESnumeric_to_long(numeric *nv, long *lp)
        errno = 0;
        *lp = strtol(s, &endptr, 10);
        if (endptr == s)
+       {
                /* this should not happen actually */
+               free(s);
                return -1;
+       }
+       free(s);
        if (errno == ERANGE)
        {
                if (*lp == LONG_MIN)
@@ -1612,7 +1616,6 @@ PGTYPESnumeric_to_long(numeric *nv, long *lp)
                        errno = PGTYPES_NUM_OVERFLOW;
                return -1;
        }
-       free(s);
        return 0;
 }
 
index d1a01b556dd42dc301aa073310dd2b82549fd1fc..b374bda724f17b682e6719eb0cca83e41ea20de4 100644 (file)
@@ -60,6 +60,7 @@ main(void)
                {
                        check_errno();
                        printf("dec[%d,0]: r: %d\n", i, r);
+                       PGTYPESdecimal_free(dec);
                        continue;
                }
                decarr = realloc(decarr, sizeof(decimal *) * (count + 1));
@@ -200,7 +201,10 @@ main(void)
        {
                dectoasc(decarr[i], buf, BUFSIZE-1, -1);
                printf("%d: %s\n", i, buf);
+
+               PGTYPESdecimal_free(decarr[i]);
        }
+       free(decarr);
 
        return (0);
 }
index 9bd05bc9e9efb5d154dffa9e305b2d02c0338aac..3b443e3ffdca1803f8c6a1a34e45a7d022278d07 100644 (file)
@@ -80,6 +80,7 @@ main(void)
                {
                        check_errno();
                        printf("dec[%d,0]: r: %d\n", i, r);
+                       PGTYPESdecimal_free(dec);
                        continue;
                }
                decarr = realloc(decarr, sizeof(decimal *) * (count + 1));
@@ -220,7 +221,10 @@ main(void)
        {
                dectoasc(decarr[i], buf, BUFSIZE-1, -1);
                printf("%d: %s\n", i, buf);
+
+               PGTYPESdecimal_free(decarr[i]);
        }
+       free(decarr);
 
        return (0);
 }
index a52ad13fb9a94342e5572ec643a7c4a85ea381bb..b0b3239b9fd7a280cfc4cf84de7a64daceb54dd6 100644 (file)
@@ -123,6 +123,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
        PGTYPESinterval_copy(iv1, &iv2);
        text = PGTYPESinterval_to_asc(&iv2);
        printf ("interval: %s\n", text);
+       PGTYPESinterval_free(iv1);
        free(text);
 
        PGTYPESdate_mdyjul(mdy, &date2);
@@ -430,16 +431,16 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
        free(text);
 
        { ECPGtrans(__LINE__, NULL, "rollback");
-#line 358 "dt_test.pgc"
+#line 359 "dt_test.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
-#line 358 "dt_test.pgc"
+#line 359 "dt_test.pgc"
 
         { ECPGdisconnect(__LINE__, "CURRENT");
-#line 359 "dt_test.pgc"
+#line 360 "dt_test.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
-#line 359 "dt_test.pgc"
+#line 360 "dt_test.pgc"
 
 
        return (0);
index 6c861fac8a450939f7b6e32f8afc826aaf3fd108..41a8013f47a2273ccad219d9f9da50d352f656db 100644 (file)
@@ -42,7 +42,7 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_get_data on line 38: RESULT: 2000-07-12 17:34:29 offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGtrans on line 358: action "rollback"; connection "regress1"
+[NO_PID]: ECPGtrans on line 359: action "rollback"; connection "regress1"
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_finish: connection regress1 closed
 [NO_PID]: sqlca: code: 0, state: 00000
index cd083f5d2e339073fd958ce2a450b5342d8ae53d..2497eb1a235884f581fa5aeb02338e1a6719401d 100644 (file)
@@ -139,6 +139,7 @@ main(void)
                                        printf("TS[%d,%d]: %s\n",
                                                i, j, errno ? "-" : text);
                                free(text);
+                               free(t);
                        }
                }
        }
@@ -169,6 +170,7 @@ main(void)
                printf("interval_copy[%d]: %s\n", i, text ? text : "-");
                free(text);
                PGTYPESinterval_free(ic);
+               PGTYPESinterval_free(i1);
        }
 
        return (0);
index 999db79a107b8b8324e0dda7062ddaf980a92ae2..077c0beee6b63a573ab56c83378fcf118d5e48d2 100644 (file)
@@ -252,17 +252,19 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 84 "nan_test.pgc"
 
 
+       PGTYPESnumeric_free(num);
+
        { ECPGtrans(__LINE__, NULL, "rollback");
-#line 86 "nan_test.pgc"
+#line 88 "nan_test.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
-#line 86 "nan_test.pgc"
+#line 88 "nan_test.pgc"
 
        { ECPGdisconnect(__LINE__, "CURRENT");
-#line 87 "nan_test.pgc"
+#line 89 "nan_test.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
-#line 87 "nan_test.pgc"
+#line 89 "nan_test.pgc"
 
 
        return (0);
index 41ed8fb885b2d786848254d79f8d31dee6e60852..d04e426aaebf64e7d76147b347649da38042c663 100644 (file)
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_execute on line 84: OK: CLOSE CURSOR
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGtrans on line 86: action "rollback"; connection "regress1"
+[NO_PID]: ECPGtrans on line 88: action "rollback"; connection "regress1"
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_finish: connection regress1 closed
 [NO_PID]: sqlca: code: 0, state: 00000
index 09554a340a4967db5cefbe9b8f29d98df9df6783..6c6eb0b23a64d5e38253bd5e0d86eaf8f49b02d0 100644 (file)
@@ -131,6 +131,9 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
        PGTYPESnumeric_to_double(res, &d);
        printf("div = %s %e\n", text, d);
 
+       PGTYPESnumeric_free(value1);
+       PGTYPESnumeric_free(value2);
+
        value1 = PGTYPESnumeric_from_asc("2E7", NULL);
        value2 = PGTYPESnumeric_from_asc("14", NULL);
        i = PGTYPESnumeric_to_long(value1, &l1) | PGTYPESnumeric_to_long(value2, &l2);
@@ -142,16 +145,16 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
        PGTYPESnumeric_free(res);
 
        { ECPGtrans(__LINE__, NULL, "rollback");
-#line 90 "num_test.pgc"
+#line 93 "num_test.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
-#line 90 "num_test.pgc"
+#line 93 "num_test.pgc"
 
        { ECPGdisconnect(__LINE__, "CURRENT");
-#line 91 "num_test.pgc"
+#line 94 "num_test.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
-#line 91 "num_test.pgc"
+#line 94 "num_test.pgc"
 
 
        return (0);
index 8e6257f0929c0de92990ffb93edf2a22f37e6d33..9557da5e88063f01828a38d0ff563f81d357a257 100644 (file)
@@ -26,7 +26,7 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_get_data on line 66: RESULT: 2369.7000000 offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGtrans on line 90: action "rollback"; connection "regress1"
+[NO_PID]: ECPGtrans on line 93: action "rollback"; connection "regress1"
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_finish: connection regress1 closed
 [NO_PID]: sqlca: code: 0, state: 00000
index 4f15226d2550cfd619e4dbf86f4a62774d5ab49c..83636ad880016b8c3768d39a0b77aaeef4dd08ad 100644 (file)
@@ -211,6 +211,11 @@ main(void)
                                printf("num[d,%d,%d]: %s\n", i, j, text);
                                free(text);
                        }
+
+                       PGTYPESnumeric_free(a);
+                       PGTYPESnumeric_free(s);
+                       PGTYPESnumeric_free(m);
+                       PGTYPESnumeric_free(d);
                }
        }
 
@@ -219,7 +224,9 @@ main(void)
                text = PGTYPESnumeric_to_asc(numarr[i], -1);
                printf("%d: %s\n", i, text);
                free(text);
+               PGTYPESnumeric_free(numarr[i]);
        }
+       free(numarr);
 
        return (0);
 }
index ade0ccb9379de8c012062dc7c95c8524594fd0c8..cdd2bea0789d6c602d78b235fdf2f853288d9536 100644 (file)
@@ -273,5 +273,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 74 "array.pgc"
 
 
+       free(t);
+
        return (0);
 }
index 3ed20614541f734fccfeaa3fe1602109ff42ca96..4e3c4404437734eed7d0bf3e745ca7ef1e9136b4 100644 (file)
@@ -49,6 +49,7 @@ main(void)
        PGTYPESinterval_copy(iv1, &iv2);
        text = PGTYPESinterval_to_asc(&iv2);
        printf ("interval: %s\n", text);
+       PGTYPESinterval_free(iv1);
        free(text);
 
        PGTYPESdate_mdyjul(mdy, &date2);
index 27d616751d979aca36398bfc860e2f53764f64cf..5ab2dfeccf76700c3e888f5ed0095005de9ace09 100644 (file)
@@ -104,6 +104,7 @@ main(void)
                                        printf("TS[%d,%d]: %s\n",
                                                i, j, errno ? "-" : text);
                                free(text);
+                               free(t);
                        }
                }
        }
@@ -134,6 +135,7 @@ main(void)
                printf("interval_copy[%d]: %s\n", i, text ? text : "-");
                free(text);
                PGTYPESinterval_free(ic);
+               PGTYPESinterval_free(i1);
        }
 
        return (0);
index 304b43816ae9d0a13b2173debf992300e7e4b303..a5cbe296a97d707ee0b0b51ab855011bd1b42779 100644 (file)
@@ -83,6 +83,8 @@ main(void)
        }
        exec sql close cur1;
 
+       PGTYPESnumeric_free(num);
+
        exec sql rollback;
        exec sql disconnect;
 
index 3d62e694b7ab0a566f5b58772e93181a0e417c43..fcdc3964356d0a68fc5be6a2141cda049b051654 100644 (file)
@@ -77,6 +77,9 @@ main(void)
        PGTYPESnumeric_to_double(res, &d);
        printf("div = %s %e\n", text, d);
 
+       PGTYPESnumeric_free(value1);
+       PGTYPESnumeric_free(value2);
+
        value1 = PGTYPESnumeric_from_asc("2E7", NULL);
        value2 = PGTYPESnumeric_from_asc("14", NULL);
        i = PGTYPESnumeric_to_long(value1, &l1) | PGTYPESnumeric_to_long(value2, &l2);
index 0b2a2e654ca60917d1376550678e9b4711c98491..2ac666f7c02153c921d7b3c8a893a0a755531b52 100644 (file)
@@ -193,6 +193,11 @@ main(void)
                                printf("num[d,%d,%d]: %s\n", i, j, text);
                                free(text);
                        }
+
+                       PGTYPESnumeric_free(a);
+                       PGTYPESnumeric_free(s);
+                       PGTYPESnumeric_free(m);
+                       PGTYPESnumeric_free(d);
                }
        }
 
@@ -201,7 +206,9 @@ main(void)
                text = PGTYPESnumeric_to_asc(numarr[i], -1);
                printf("%d: %s\n", i, text);
                free(text);
+               PGTYPESnumeric_free(numarr[i]);
        }
+       free(numarr);
 
        return (0);
 }
index d589a242f57c8985db7b572be9d148860efaf80f..d74a1354e5f96d18c83d286739185ee5ce754c22 100644 (file)
@@ -73,5 +73,7 @@ EXEC SQL END DECLARE SECTION;
 
        EXEC SQL DISCONNECT;
 
+       free(t);
+
        return (0);
 }