@@ -803,7 +803,10 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
803803
804804mallocedval = quote_postgres (newcopy ,quote ,lineno );
805805if (!mallocedval )
806+ {
807+ ecpg_free (newcopy );
806808return false;
809+ }
807810
808811* tobeinserted_p = mallocedval ;
809812}
@@ -835,7 +838,10 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
835838
836839mallocedval = quote_postgres (newcopy ,quote ,lineno );
837840if (!mallocedval )
841+ {
842+ ecpg_free (newcopy );
838843return false;
844+ }
839845
840846* tobeinserted_p = mallocedval ;
841847}
@@ -859,7 +865,10 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
859865
860866nval = PGTYPESnumeric_new ();
861867if (!nval )
868+ {
869+ ecpg_free (mallocedval );
862870return false;
871+ }
863872
864873if (var -> type == ECPGt_numeric )
865874result = PGTYPESnumeric_copy ((numeric * ) ((var + var -> offset * element )-> value ),nval );
@@ -869,18 +878,21 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
869878if (result != 0 )
870879{
871880PGTYPESnumeric_free (nval );
881+ ecpg_free (mallocedval );
872882return false;
873883}
874884
875885str = PGTYPESnumeric_to_asc (nval ,nval -> dscale );
876886slen = strlen (str );
877887PGTYPESnumeric_free (nval );
878888
879- if (!(mallocedval = ecpg_realloc (mallocedval ,strlen (mallocedval )+ slen + 2 ,lineno )))
889+ if (!(newcopy = ecpg_realloc (mallocedval ,strlen (mallocedval )+ slen + 2 ,lineno )))
880890{
891+ ecpg_free (mallocedval );
881892ecpg_free (str );
882893return false;
883894}
895+ mallocedval = newcopy ;
884896
885897memcpy (mallocedval + strlen (mallocedval ),str ,slen + 1 );
886898strcpy (mallocedval + strlen (mallocedval ),"," );
@@ -940,14 +952,19 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
940952{
941953str = quote_postgres (PGTYPESinterval_to_asc ((interval * ) ((var + var -> offset * element )-> value )),quote ,lineno );
942954if (!str )
955+ {
956+ ecpg_free (mallocedval );
943957return false;
958+ }
944959slen = strlen (str );
945960
946- if (!(mallocedval = ecpg_realloc (mallocedval ,strlen (mallocedval )+ slen + 2 ,lineno )))
961+ if (!(newcopy = ecpg_realloc (mallocedval ,strlen (mallocedval )+ slen + 2 ,lineno )))
947962{
963+ ecpg_free (mallocedval );
948964ecpg_free (str );
949965return false;
950966}
967+ mallocedval = newcopy ;
951968
952969memcpy (mallocedval + strlen (mallocedval ),str ,slen + 1 );
953970strcpy (mallocedval + strlen (mallocedval ),"," );
@@ -991,14 +1008,19 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
9911008{
9921009str = quote_postgres (PGTYPESdate_to_asc (* (date * ) ((var + var -> offset * element )-> value )),quote ,lineno );
9931010if (!str )
1011+ {
1012+ ecpg_free (mallocedval );
9941013return false;
1014+ }
9951015slen = strlen (str );
9961016
997- if (!(mallocedval = ecpg_realloc (mallocedval ,strlen (mallocedval )+ slen + 2 ,lineno )))
1017+ if (!(newcopy = ecpg_realloc (mallocedval ,strlen (mallocedval )+ slen + 2 ,lineno )))
9981018{
1019+ ecpg_free (mallocedval );
9991020ecpg_free (str );
10001021return false;
10011022}
1023+ mallocedval = newcopy ;
10021024
10031025memcpy (mallocedval + strlen (mallocedval ),str ,slen + 1 );
10041026strcpy (mallocedval + strlen (mallocedval ),"," );
@@ -1049,11 +1071,13 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
10491071
10501072slen = strlen (str );
10511073
1052- if (!(mallocedval = ecpg_realloc (mallocedval ,strlen (mallocedval )+ slen + 2 ,lineno )))
1074+ if (!(newcopy = ecpg_realloc (mallocedval ,strlen (mallocedval )+ slen + 2 ,lineno )))
10531075{
1076+ ecpg_free (mallocedval );
10541077ecpg_free (str );
10551078return false;
10561079}
1080+ mallocedval = newcopy ;
10571081
10581082memcpy (mallocedval + strlen (mallocedval ),str ,slen + 1 );
10591083strcpy (mallocedval + strlen (mallocedval ),"," );