diff --git a/contrib/dblink/dblink.cpp b/contrib/dblink/dblink.cpp index d1cc54ee6..842ab1bef 100644 --- a/contrib/dblink/dblink.cpp +++ b/contrib/dblink/dblink.cpp @@ -974,10 +974,10 @@ Datum dblink_open(PG_FUNCTION_ARGS) rconn = getConnectionByName(conname); } - linker = rconn->linker; - if (linker == NULL) { + if (rconn == NULL || rconn->linker == NULL) { DBLINK_CONN_NOT_AVAIL; } + linker = rconn->linker; /* Assemble sql */ appendStringInfo(&buf, "DECLARE %s CURSOR FOR %s", curname, sql); @@ -1028,10 +1028,10 @@ Datum dblink_close(PG_FUNCTION_ARGS) rconn = getConnectionByName(conname); } - linker = rconn->linker; - if (linker == NULL) { + if (rconn == NULL || rconn->linker == NULL) { DBLINK_CONN_NOT_AVAIL; } + linker = rconn->linker; appendStringInfo(&buf, "CLOSE %s", curname); @@ -3113,4 +3113,4 @@ static void storeRowInit(storeInfo* sinfo, int nfields, bool first) ALLOCSET_DEFAULT_INITSIZE, ALLOCSET_DEFAULT_MAXSIZE); } -} \ No newline at end of file +}