Check for non-existant connection in prepare statement handling.
authorMichael Meskes <meskes@postgresql.org>
Mon, 12 May 2008 16:30:17 +0000 (16:30 +0000)
committerMichael Meskes <meskes@postgresql.org>
Mon, 12 May 2008 16:30:17 +0000 (16:30 +0000)
Do not close files that weren't opened.

src/interfaces/ecpg/ecpglib/prepare.c
src/interfaces/ecpg/preproc/preproc.y

index e1cc60ee19fc38d0242d4709aedd80994b6194ce..f20c7e7bad688f56217e6d35b4aad76e4b15cd60 100644 (file)
@@ -120,10 +120,11 @@ ECPGprepare(int lineno, const char *connection_name, const int questionmarks, co
        struct sqlca_t *sqlca = ECPGget_sqlca();
        PGresult   *query;
 
-       ecpg_init_sqlca(sqlca);
-
        con = ecpg_get_connection(connection_name);
 
+       if (!ecpg_init(con, connection_name, lineno))
+               return false;
+
        /* check if we already have prepared this statement */
        this = find_prepared_statement(name, con, &prev);
        if (this && !deallocate_one(lineno, ECPG_COMPAT_PGSQL, con, prev, this))
@@ -256,6 +257,9 @@ ECPGdeallocate(int lineno, int c, const char *connection_name, const char *name)
 
        con = ecpg_get_connection(connection_name);
 
+       if (!ecpg_init(con, connection_name, lineno))
+               return false;
+
        this = find_prepared_statement(name, con, &prev);
        if (this)
                return deallocate_one(lineno, c, con, prev, this);
index 1b6763b23f6375adb583e52b77c2d756eac9d6d0..2d953a9f6f1a3abca8ae5a1372691e8205d8094f 100644 (file)
@@ -87,8 +87,10 @@ mmerror(int error_code, enum errortype type, char * error, ...)
                        ret_value = error_code;
                        break;
                case ET_FATAL:
-                       fclose(yyin);
-                       fclose(yyout);
+                       if (yyin)
+                               fclose(yyin);
+                       if (yyout)
+                               fclose(yyout);
                        if (unlink(output_filename) != 0 && *output_filename != '-')
                                fprintf(stderr, "Could not remove output file %s!\n", output_filename);
                        exit(error_code);