diff --git a/contrib/babelfishpg_tsql/runtime/functions.c b/contrib/babelfishpg_tsql/runtime/functions.c index 12d4adf8e1..a12b1ad58b 100644 --- a/contrib/babelfishpg_tsql/runtime/functions.c +++ b/contrib/babelfishpg_tsql/runtime/functions.c @@ -1310,7 +1310,8 @@ schema_id(PG_FUNCTION_ARGS) if (!user) { pfree(db_name); - pfree(guest_role_name); + if(guest_role_name) + pfree(guest_role_name); PG_RETURN_NULL(); } else if ((guest_role_name && strcmp(user, guest_role_name) == 0)) @@ -1323,7 +1324,8 @@ schema_id(PG_FUNCTION_ARGS) physical_name = get_physical_schema_name(db_name, name); } pfree(db_name); - pfree(guest_role_name); + if(guest_role_name) + pfree(guest_role_name); } else { @@ -2224,14 +2226,15 @@ object_id(PG_FUNCTION_ARGS) * name */ const char *user = get_user_for_database(db_name); - char *guest_role_name = get_guest_role_name(db_name); + char *guest_role_name = get_guest_role_name(db_name); if (!user) { pfree(db_name); pfree(schema_name); pfree(object_name); - pfree(guest_role_name); + if(guest_role_name) + pfree(guest_role_name); if (object_type) pfree(object_type); PG_RETURN_NULL(); @@ -2246,7 +2249,8 @@ object_id(PG_FUNCTION_ARGS) schema_name = get_authid_user_ext_schema_name((const char *) db_name, user); physical_schema_name = get_physical_schema_name(db_name, schema_name); } - pfree(guest_role_name); + if(guest_role_name) + pfree(guest_role_name); } else { @@ -2687,7 +2691,8 @@ type_id(PG_FUNCTION_ARGS) pfree(db_name); pfree(schema_name); pfree(object_name); - pfree(guest_role_name); + if(guest_role_name) + pfree(guest_role_name); PG_RETURN_NULL(); } else if ((guest_role_name && strcmp(user, guest_role_name) == 0)) @@ -2700,7 +2705,8 @@ type_id(PG_FUNCTION_ARGS) schema_name = get_authid_user_ext_schema_name((const char *) db_name, user); physical_schema_name = get_physical_schema_name(db_name, schema_name); } - pfree(guest_role_name); + if(guest_role_name) + pfree(guest_role_name); } else { diff --git a/contrib/babelfishpg_tsql/src/catalog.c b/contrib/babelfishpg_tsql/src/catalog.c index 3bea8451c4..9bd6885127 100644 --- a/contrib/babelfishpg_tsql/src/catalog.c +++ b/contrib/babelfishpg_tsql/src/catalog.c @@ -3121,7 +3121,9 @@ guest_role_exists_for_db(const char *dbname) systable_endscan(scan); table_close(bbf_authid_user_ext_rel, RowExclusiveLock); - pfree(guest_role); + + if(guest_role) + pfree(guest_role); return role_exists; } @@ -3218,7 +3220,8 @@ create_guest_role_for_db(const char *dbname) SetConfigOption("createrole_self_grant", old_createrole_self_grant, PGC_USERSET, PGC_S_OVERRIDE); SetUserIdAndSecContext(save_userid, save_sec_context); set_cur_db(old_dbid, old_dbname); - pfree(guest); + if(guest) + pfree(guest); } PG_END_TRY(); } diff --git a/contrib/babelfishpg_tsql/src/dbcmds.c b/contrib/babelfishpg_tsql/src/dbcmds.c index cc2ffb6cd2..7fdad52df3 100644 --- a/contrib/babelfishpg_tsql/src/dbcmds.c +++ b/contrib/babelfishpg_tsql/src/dbcmds.c @@ -647,8 +647,10 @@ create_bbf_db_internal(ParseState *pstate, const char *dbname, List *options, co SetConfigOption("createrole_self_grant", old_createrole_self_grant, PGC_USERSET, PGC_S_OVERRIDE); SetUserIdAndSecContext(save_userid, save_sec_context); set_cur_db(old_dbid, old_dbname); - pfree(dbo_scm); - pfree(guest_scm); + if(dbo_scm) + pfree(dbo_scm); + if(guest_scm) + pfree(guest_scm); } PG_END_TRY(); } @@ -833,10 +835,14 @@ drop_bbf_db(const char *dbname, bool missing_ok, bool force_drop) } PG_END_TRY(); - pfree(schema_name); - pfree(db_owner_role); - pfree(dbo_role); - pfree(guest_schema_name); + if(schema_name) + pfree(schema_name); + if(db_owner_role) + pfree(db_owner_role); + if(dbo_role) + pfree(dbo_role); + if(guest_schema_name) + pfree(guest_schema_name); /* Set current user back to previous user */ bbf_set_current_user(prev_current_user); diff --git a/contrib/babelfishpg_tsql/src/hooks.c b/contrib/babelfishpg_tsql/src/hooks.c index 5ce754a518..7d32e17998 100644 --- a/contrib/babelfishpg_tsql/src/hooks.c +++ b/contrib/babelfishpg_tsql/src/hooks.c @@ -4949,9 +4949,9 @@ get_local_schema_for_bbf_functions(Oid proc_nsp_oid) quote_identifier(func_dbo_schema)); ReleaseSysCache(tuple); + if(func_dbo_schema) + pfree(func_dbo_schema); } - - pfree(func_dbo_schema); return new_search_path; } diff --git a/contrib/babelfishpg_tsql/src/pl_exec-2.c b/contrib/babelfishpg_tsql/src/pl_exec-2.c index eca36fc5e6..d667137770 100644 --- a/contrib/babelfishpg_tsql/src/pl_exec-2.c +++ b/contrib/babelfishpg_tsql/src/pl_exec-2.c @@ -3347,8 +3347,10 @@ void exec_stmt_dbcc_checkident(PLtsql_stmt_dbcc *stmt) } } pfree(db_name); - pfree(guest_role_name); - pfree(dbo_role_name); + if(guest_role_name) + pfree(guest_role_name); + if(dbo_role_name) + pfree(dbo_role_name); /* * get schema oid from physical schema name, it will return InvalidOid if @@ -3402,8 +3404,8 @@ void exec_stmt_dbcc_checkident(PLtsql_stmt_dbcc *stmt) errmsg("'%s.%s' does not contain an identity column.", nsp_name, dbcc_stmt.table_name))); } - - pfree(nsp_name); + if(nsp_name) + pfree(nsp_name); PG_TRY(); { diff --git a/contrib/babelfishpg_tsql/src/pl_handler.c b/contrib/babelfishpg_tsql/src/pl_handler.c index b22c836837..cb901878d0 100644 --- a/contrib/babelfishpg_tsql/src/pl_handler.c +++ b/contrib/babelfishpg_tsql/src/pl_handler.c @@ -3283,7 +3283,8 @@ bbf_ProcessUtility(PlannedStmt *pstmt, set_session_properties(db_name); pfree(cur_user); pfree(db_name); - pfree(dbo_name); + if(dbo_name) + pfree(dbo_name); return; } @@ -3408,7 +3409,8 @@ bbf_ProcessUtility(PlannedStmt *pstmt, } pfree(rolspec->rolename); - pfree(db_owner_name); + if(db_owner_name) + pfree(db_owner_name); rolspec->rolename = user_name; } } diff --git a/contrib/babelfishpg_tsql/src/procedures.c b/contrib/babelfishpg_tsql/src/procedures.c index 420c62ecfc..fb2d5bd991 100644 --- a/contrib/babelfishpg_tsql/src/procedures.c +++ b/contrib/babelfishpg_tsql/src/procedures.c @@ -3379,7 +3379,8 @@ sp_babelfish_volatility(PG_FUNCTION_ARGS) physical_schema_name = get_physical_schema_name(db_name, logical_schema_name); pfree(logical_schema_name); } - pfree(guest_role_name); + if(guest_role_name) + pfree(guest_role_name); } else { diff --git a/contrib/babelfishpg_tsql/src/rolecmds.c b/contrib/babelfishpg_tsql/src/rolecmds.c index f01757ad53..8323a85d71 100644 --- a/contrib/babelfishpg_tsql/src/rolecmds.c +++ b/contrib/babelfishpg_tsql/src/rolecmds.c @@ -661,7 +661,8 @@ grant_revoke_dbo_to_login(const char* login, const char* db_name, bool is_grant) CommandCounterIncrement(); pfree(query.data); - pfree(dbo_role_name); + if(dbo_role_name) + pfree(dbo_role_name); } static List * @@ -1990,20 +1991,26 @@ is_rolemember(PG_FUNCTION_ARGS) dbo_role_oid = get_role_oid(dbo_role_name, false); if ((principal_oid == db_owner_oid) || (principal_oid == dbo_role_oid)) { - pfree(db_owner_name); - pfree(dbo_role_name); + if(db_owner_name) + pfree(db_owner_name); + if(dbo_role_name) + pfree(dbo_role_name); PG_RETURN_INT32(0); } else if (is_member_of_role_nosuper(principal_oid, role_oid)) { - pfree(db_owner_name); - pfree(dbo_role_name); + if(db_owner_name) + pfree(db_owner_name); + if(dbo_role_name) + pfree(dbo_role_name); PG_RETURN_INT32(1); } else { - pfree(db_owner_name); - pfree(dbo_role_name); + if(db_owner_name) + pfree(db_owner_name); + if(dbo_role_name) + pfree(dbo_role_name); PG_RETURN_INT32(0); } } diff --git a/contrib/babelfishpg_tsql/src/session.c b/contrib/babelfishpg_tsql/src/session.c index 9b7acd353d..8bc5f7d375 100644 --- a/contrib/babelfishpg_tsql/src/session.c +++ b/contrib/babelfishpg_tsql/src/session.c @@ -197,9 +197,12 @@ set_search_path_for_user_schema(const char *db_name, const char *user) PGC_SUSET, PGC_S_DATABASE_USER); - pfree(dbo_role_name); - pfree(guest_role_name); - pfree(physical_schema); + if(dbo_role_name) + pfree(dbo_role_name); + if(guest_role_name) + pfree(guest_role_name); + if(physical_schema) + pfree(physical_schema); } /*