Possible database leaks fixed

This commit is contained in:
Beny 2019-05-23 23:57:22 +01:00
parent 59613f8900
commit 2e66d305d4
12 changed files with 166 additions and 93 deletions

View File

@ -212,8 +212,6 @@ public class CatalogManager
{ {
Emulator.getPluginManager().fireEvent(new EmulatorLoadCatalogManagerEvent()); Emulator.getPluginManager().fireEvent(new EmulatorLoadCatalogManagerEvent());
try
{
this.loadLimitedNumbers(); this.loadLimitedNumbers();
this.loadCatalogPages(); this.loadCatalogPages();
this.loadCatalogFeaturedPages(); this.loadCatalogFeaturedPages();
@ -226,13 +224,8 @@ public class CatalogManager
this.loadGiftWrappers(); this.loadGiftWrappers();
this.loadCalendarRewards(); this.loadCalendarRewards();
} }
catch(SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
}
private synchronized void loadLimitedNumbers() throws SQLException private synchronized void loadLimitedNumbers()
{ {
this.limitedNumbers.clear(); this.limitedNumbers.clear();
@ -270,12 +263,12 @@ public class CatalogManager
} }
private synchronized void loadCatalogPages() throws SQLException private synchronized void loadCatalogPages()
{ {
this.catalogPages.clear(); this.catalogPages.clear();
final THashMap<Integer, CatalogPage> pages = new THashMap<>(); final THashMap<Integer, CatalogPage> pages = new THashMap<>();
pages.put(-1, new CatalogRootLayout(null)); pages.put(-1, new CatalogRootLayout());
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM catalog_pages ORDER BY parent_id, id")) try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM catalog_pages ORDER BY parent_id, id"))
{ {
try (ResultSet set = statement.executeQuery()) try (ResultSet set = statement.executeQuery())
@ -338,7 +331,7 @@ public class CatalogManager
} }
private synchronized void loadCatalogFeaturedPages() throws SQLException private synchronized void loadCatalogFeaturedPages()
{ {
this.catalogFeaturedPages.clear(); this.catalogFeaturedPages.clear();
@ -364,7 +357,7 @@ public class CatalogManager
} }
} }
private synchronized void loadCatalogItems() throws SQLException private synchronized void loadCatalogItems()
{ {
this.clubItems.clear(); this.clubItems.clear();
catalogItemAmount = 0; catalogItemAmount = 0;
@ -431,7 +424,7 @@ public class CatalogManager
} }
} }
private void loadClubOffers() throws SQLException private void loadClubOffers()
{ {
this.clubOffers.clear(); this.clubOffers.clear();
@ -446,9 +439,13 @@ public class CatalogManager
} }
} }
} }
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
} }
private void loadTargetOffers() throws SQLException private void loadTargetOffers()
{ {
synchronized (this.targetOffers) synchronized (this.targetOffers)
{ {
@ -465,11 +462,15 @@ public class CatalogManager
} }
} }
} }
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
} }
} }
private void loadVouchers() throws SQLException private void loadVouchers()
{ {
synchronized (this.vouchers) synchronized (this.vouchers)
{ {
@ -482,11 +483,15 @@ public class CatalogManager
this.vouchers.add(new Voucher(set)); this.vouchers.add(new Voucher(set));
} }
} }
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
} }
} }
public void loadRecycler() throws SQLException public void loadRecycler()
{ {
synchronized (this.prizes) synchronized (this.prizes)
{ {
@ -520,7 +525,7 @@ public class CatalogManager
} }
public void loadGiftWrappers() throws SQLException public void loadGiftWrappers()
{ {
synchronized (this.giftWrappers) synchronized (this.giftWrappers)
{ {

View File

@ -39,6 +39,10 @@ public abstract class CatalogPage implements Comparable<CatalogPage>, ISerialize
private final TIntObjectMap<CatalogItem> catalogItems = TCollections.synchronizedMap(new TIntObjectHashMap<>()); private final TIntObjectMap<CatalogItem> catalogItems = TCollections.synchronizedMap(new TIntObjectHashMap<>());
private final ArrayList<Integer> included = new ArrayList<>(); private final ArrayList<Integer> included = new ArrayList<>();
public CatalogPage()
{
}
public CatalogPage(ResultSet set) throws SQLException public CatalogPage(ResultSet set) throws SQLException
{ {
if (set == null) if (set == null)

View File

@ -8,6 +8,11 @@ import java.sql.SQLException;
public class CatalogRootLayout extends CatalogPage public class CatalogRootLayout extends CatalogPage
{ {
public CatalogRootLayout()
{
super();
}
public CatalogRootLayout(ResultSet set) throws SQLException public CatalogRootLayout(ResultSet set) throws SQLException
{ {
super(null); super(null);

View File

@ -368,7 +368,7 @@ public class MarketPlace
} }
public static void sendErrorMessage(GameClient client, int baseItemId, int offerId) throws SQLException public static void sendErrorMessage(GameClient client, int baseItemId, int offerId)
{ {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT marketplace_items.*, COUNT( * ) AS count\n" + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT marketplace_items.*, COUNT( * ) AS count\n" +
"FROM marketplace_items\n" + "FROM marketplace_items\n" +
@ -394,6 +394,10 @@ public class MarketPlace
} }
} }
} }
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
} }
@ -412,8 +416,7 @@ public class MarketPlace
} }
RequestOffersEvent.cachedResults.clear(); RequestOffersEvent.cachedResults.clear();
try
{
client.sendResponse(new RemoveHabboItemComposer(event.item.getGiftAdjustedId())); client.sendResponse(new RemoveHabboItemComposer(event.item.getGiftAdjustedId()));
client.sendResponse(new InventoryRefreshComposer()); client.sendResponse(new InventoryRefreshComposer());
@ -425,11 +428,6 @@ public class MarketPlace
item.setUserId(-1); item.setUserId(-1);
item.needsUpdate(true); item.needsUpdate(true);
Emulator.getThreading().run(item); Emulator.getThreading().run(item);
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
return true; return true;
} }

View File

@ -48,7 +48,7 @@ public class MarketPlaceOffer implements Runnable
} }
} }
public MarketPlaceOffer(HabboItem item, int price, Habbo habbo) throws SQLException public MarketPlaceOffer(HabboItem item, int price, Habbo habbo)
{ {
this.price = price; this.price = price;
this.baseItem = item.getBaseItem(); this.baseItem = item.getBaseItem();
@ -76,6 +76,10 @@ public class MarketPlaceOffer implements Runnable
} }
} }
} }
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
} }
public int getOfferId() public int getOfferId()

View File

@ -349,7 +349,7 @@ public class ForumThread implements Runnable, ISerialize {
return createdThread; return createdThread;
} }
public static THashSet<ForumThread> getByGuildId(int guildId) throws SQLException { public static THashSet<ForumThread> getByGuildId(int guildId) {
THashSet<ForumThread> threads = null; THashSet<ForumThread> threads = null;
if(guildThreadsCache.containsKey(guildId)) { if(guildThreadsCache.containsKey(guildId)) {
@ -381,9 +381,9 @@ public class ForumThread implements Runnable, ISerialize {
)) ))
{ {
statement.setInt(1, guildId); statement.setInt(1, guildId);
ResultSet set = statement.executeQuery();
while(set.next()) { try(ResultSet set = statement.executeQuery()) {
while (set.next()) {
ForumThread thread = new ForumThread(set); ForumThread thread = new ForumThread(set);
synchronized (threads) { synchronized (threads) {
threads.add(thread); threads.add(thread);
@ -391,6 +391,7 @@ public class ForumThread implements Runnable, ISerialize {
cacheThread(thread); cacheThread(thread);
} }
} }
}
catch (SQLException e) catch (SQLException e)
{ {
Emulator.getLogging().logSQLException(e); Emulator.getLogging().logSQLException(e);
@ -425,13 +426,14 @@ public class ForumThread implements Runnable, ISerialize {
)) ))
{ {
statement.setInt(1, threadId); statement.setInt(1, threadId);
ResultSet set = statement.executeQuery();
while(set.next()) { try(ResultSet set = statement.executeQuery()) {
while (set.next()) {
foundThread = new ForumThread(set); foundThread = new ForumThread(set);
cacheThread(foundThread); cacheThread(foundThread);
} }
} }
}
catch (SQLException e) catch (SQLException e)
{ {
Emulator.getLogging().logSQLException(e); Emulator.getLogging().logSQLException(e);

View File

@ -57,13 +57,14 @@ public class ForumThreadComment implements Runnable, ISerialize {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM `guilds_forums_comments` WHERE `id` = ? LIMIT 1")) try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM `guilds_forums_comments` WHERE `id` = ? LIMIT 1"))
{ {
statement.setInt(1, id); statement.setInt(1, id);
ResultSet set = statement.executeQuery();
while(set.next()) { try(ResultSet set = statement.executeQuery()) {
while (set.next()) {
foundComment = new ForumThreadComment(set); foundComment = new ForumThreadComment(set);
cacheComment(foundComment); cacheComment(foundComment);
} }
} }
}
catch (SQLException e) catch (SQLException e)
{ {
Emulator.getLogging().logSQLException(e); Emulator.getLogging().logSQLException(e);

View File

@ -68,7 +68,7 @@ public class ModToolManager
} }
} }
private void loadCategory(Connection connection) throws SQLException private void loadCategory(Connection connection)
{ {
try (Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM support_issue_categories")) try (Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM support_issue_categories"))
{ {
@ -89,9 +89,13 @@ public class ModToolManager
} }
} }
} }
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
} }
private void loadPresets(Connection connection) throws SQLException private void loadPresets(Connection connection)
{ {
synchronized (this.presets) synchronized (this.presets)
{ {
@ -102,10 +106,14 @@ public class ModToolManager
this.presets.get(set.getString("type")).add(set.getString("preset")); this.presets.get(set.getString("type")).add(set.getString("preset"));
} }
} }
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
} }
} }
private void loadTickets(Connection connection) throws SQLException private void loadTickets(Connection connection)
{ {
synchronized (this.tickets) synchronized (this.tickets)
{ {
@ -116,10 +124,14 @@ public class ModToolManager
this.tickets.put(set.getInt("id"), new ModToolIssue(set)); this.tickets.put(set.getInt("id"), new ModToolIssue(set));
} }
} }
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
} }
} }
private void loadCfhCategories(Connection connection) throws SQLException private void loadCfhCategories(Connection connection)
{ {
try (Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT " + try (Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT " +
"support_cfh_topics.id, " + "support_cfh_topics.id, " +
@ -144,6 +156,10 @@ public class ModToolManager
this.cfhCategories.get(set.getInt("support_cfh_category_id")).addTopic(new CfhTopic(set, this.getIssuePreset(set.getInt("default_sanction")))); this.cfhCategories.get(set.getInt("support_cfh_category_id")).addTopic(new CfhTopic(set, this.getIssuePreset(set.getInt("default_sanction"))));
} }
} }
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
} }
public CfhTopic getCfhTopic(int topicId) public CfhTopic getCfhTopic(int topicId)

View File

@ -106,7 +106,7 @@ public class PetManager
} }
} }
private void loadRaces(Connection connection) throws SQLException private void loadRaces(Connection connection)
{ {
this.petRaces.clear(); this.petRaces.clear();
@ -120,9 +120,13 @@ public class PetManager
this.petRaces.get(set.getInt("race")).add(new PetRace(set)); this.petRaces.get(set.getInt("race")).add(new PetRace(set));
} }
} }
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
} }
private void loadPetData(Connection connection) throws SQLException private void loadPetData(Connection connection)
{ {
try (Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM pet_actions ORDER BY pet_type ASC")) try (Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM pet_actions ORDER BY pet_type ASC"))
{ {
@ -131,13 +135,17 @@ public class PetManager
this.petData.put(set.getInt("pet_type"), new PetData(set)); this.petData.put(set.getInt("pet_type"), new PetData(set));
} }
} }
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
this.loadPetItems(connection); this.loadPetItems(connection);
this.loadPetVocals(connection); this.loadPetVocals(connection);
} }
private void loadPetItems(Connection connection) throws SQLException private void loadPetItems(Connection connection)
{ {
try (Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM pet_items")) try (Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM pet_items"))
{ {
@ -169,9 +177,13 @@ public class PetManager
} }
} }
} }
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
} }
private void loadPetVocals(Connection connection) throws SQLException private void loadPetVocals(Connection connection)
{ {
try (Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM pet_vocals")) try (Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM pet_vocals"))
{ {
@ -206,9 +218,13 @@ public class PetManager
} }
} }
} }
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
} }
private void loadPetCommands(Connection connection) throws SQLException private void loadPetCommands(Connection connection)
{ {
THashMap<Integer, PetCommand> commandsList = new THashMap<>(); THashMap<Integer, PetCommand> commandsList = new THashMap<>();
try (Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM pet_commands_data")) try (Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM pet_commands_data"))
@ -218,6 +234,10 @@ public class PetManager
commandsList.put(set.getInt("command_id"), new PetCommand(set, this.petActions.get(set.getInt("command_id")))); commandsList.put(set.getInt("command_id"), new PetCommand(set, this.petActions.get(set.getInt("command_id"))));
} }
} }
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
try (Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM pet_commands ORDER BY pet_id ASC")) try (Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM pet_commands ORDER BY pet_id ASC"))
{ {
@ -231,9 +251,13 @@ public class PetManager
} }
} }
} }
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
} }
private void loadPetBreeding(Connection connection) throws SQLException private void loadPetBreeding(Connection connection)
{ {
try (Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM pet_breeding")) try (Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM pet_breeding"))
{ {
@ -242,6 +266,10 @@ public class PetManager
this.breedingPetType.put(set.getInt("pet_id"), set.getInt("offspring_id")); this.breedingPetType.put(set.getInt("pet_id"), set.getInt("offspring_id"));
} }
} }
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
try (Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM pet_breeding_races")) try (Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM pet_breeding_races"))
{ {
@ -261,6 +289,10 @@ public class PetManager
this.breedingReward.get(reward.petType).get(reward.rarityLevel).add(reward); this.breedingReward.get(reward.petType).get(reward.rarityLevel).add(reward);
} }
} }
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
} }
public THashSet<PetRace> getBreeds(String petName) public THashSet<PetRace> getBreeds(String petName)

View File

@ -242,17 +242,6 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
this.bannedHabbos = new TIntObjectHashMap<>(); this.bannedHabbos = new TIntObjectHashMap<>();
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM room_promotions WHERE room_id = ? AND end_timestamp > ? LIMIT 1")) try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM room_promotions WHERE room_id = ? AND end_timestamp > ? LIMIT 1"))
{ {
if(this.promoted) if(this.promoted)
@ -273,6 +262,11 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
this.loadBans(connection); this.loadBans(connection);
} }
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
this.tradeMode = set.getInt("trade_mode"); this.tradeMode = set.getInt("trade_mode");
this.moveDiagonally = set.getString("move_diagonally").equals("1"); this.moveDiagonally = set.getString("move_diagonally").equals("1");
@ -456,7 +450,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
} }
} }
private synchronized void loadItems(Connection connection) throws SQLException private synchronized void loadItems(Connection connection)
{ {
this.roomItems.clear(); this.roomItems.clear();
@ -471,9 +465,13 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
} }
} }
} }
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
} }
private synchronized void loadWiredData(Connection connection) throws SQLException private synchronized void loadWiredData(Connection connection)
{ {
try (PreparedStatement statement = connection.prepareStatement("SELECT id, wired_data FROM items WHERE room_id = ? AND wired_data<>''")) try (PreparedStatement statement = connection.prepareStatement("SELECT id, wired_data FROM items WHERE room_id = ? AND wired_data<>''"))
{ {
@ -499,13 +497,17 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
} }
} }
} }
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
catch (Exception e) catch (Exception e)
{ {
Emulator.getLogging().logErrorLine(e); Emulator.getLogging().logErrorLine(e);
} }
} }
private synchronized void loadBots(Connection connection) throws SQLException private synchronized void loadBots(Connection connection)
{ {
this.currentBots.clear(); this.currentBots.clear();
@ -550,7 +552,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
} }
} }
private synchronized void loadPets(Connection connection) throws SQLException private synchronized void loadPets(Connection connection)
{ {
this.currentPets.clear(); this.currentPets.clear();
@ -591,9 +593,13 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
} }
} }
} }
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
} }
private synchronized void loadWordFilter(Connection connection) throws SQLException private synchronized void loadWordFilter(Connection connection)
{ {
this.wordFilterWords.clear(); this.wordFilterWords.clear();
@ -608,6 +614,10 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
} }
} }
} }
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
} }
public void updateTile(RoomTile tile) public void updateTile(RoomTile tile)

View File

@ -93,7 +93,7 @@ public class GuildForumDataComposer extends MessageComposer {
return this.response; return this.response;
} }
public static void serializeForumData(ServerMessage response, Guild guild, Habbo habbo) throws SQLException { public static void serializeForumData(ServerMessage response, Guild guild, Habbo habbo) {
final THashSet<ForumThread> forumThreads = ForumThread.getByGuildId(guild.getId()); final THashSet<ForumThread> forumThreads = ForumThread.getByGuildId(guild.getId());
int lastSeenAt = 0; int lastSeenAt = 0;

View File

@ -47,11 +47,7 @@ public class GuildForumListComposer extends MessageComposer {
if(!it.hasNext()) if(!it.hasNext())
break; break;
try {
GuildForumDataComposer.serializeForumData(this.response, it.next(), habbo); GuildForumDataComposer.serializeForumData(this.response, it.next(), habbo);
} catch (SQLException e) {
return new ConnectionErrorComposer(500).compose();
}
} }
return this.response; return this.response;