workaround potencial memory leaks

LSLKeyTest
UbitUmarov 2016-08-22 06:03:39 +01:00
parent 52a80f1742
commit 5d5bad5fc1
3 changed files with 66 additions and 61 deletions

View File

@ -316,15 +316,16 @@ namespace OpenSim.Data.MySQL
return 0; return 0;
} }
MySqlCommand cmd = conn.CreateCommand(); using(MySqlCommand cmd = conn.CreateCommand())
cmd.CommandText = String.Format("select count(*) as count from {0}", m_Table);
using (IDataReader reader = cmd.ExecuteReader())
{ {
reader.Read(); cmd.CommandText = String.Format("select count(*) as count from {0}",m_Table);
count = Convert.ToInt32(reader["count"]); using (IDataReader reader = cmd.ExecuteReader())
{
reader.Read();
count = Convert.ToInt32(reader["count"]);
}
} }
} }
@ -333,15 +334,15 @@ namespace OpenSim.Data.MySQL
public bool Delete(string id) public bool Delete(string id)
{ {
MySqlCommand cmd = new MySqlCommand(); using(MySqlCommand cmd = new MySqlCommand())
{
cmd.CommandText = String.Format("delete from {0} where id = ?id", m_Table); cmd.CommandText = String.Format("delete from {0} where id = ?id",m_Table);
cmd.Parameters.AddWithValue("?id", id); cmd.Parameters.AddWithValue("?id", id);
ExecuteNonQuery(cmd); ExecuteNonQuery(cmd);
}
cmd.Dispose();
return true; return true;
} }

View File

@ -440,37 +440,39 @@ namespace OpenSim.Data.MySQL
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{ {
dbcon.Open(); dbcon.Open();
MySqlCommand cmd = new MySqlCommand("SELECT Name, Description, AccessTime, AssetType, Temporary, ID, AssetFlags, CreatorID FROM XAssetsMeta LIMIT ?start, ?count", dbcon); using(MySqlCommand cmd = new MySqlCommand("SELECT Name, Description, AccessTime, AssetType, Temporary, ID, AssetFlags, CreatorID FROM XAssetsMeta LIMIT ?start, ?count",dbcon))
cmd.Parameters.AddWithValue("?start", start);
cmd.Parameters.AddWithValue("?count", count);
try
{ {
using (MySqlDataReader dbReader = cmd.ExecuteReader()) cmd.Parameters.AddWithValue("?start",start);
cmd.Parameters.AddWithValue("?count", count);
try
{ {
while (dbReader.Read()) using (MySqlDataReader dbReader = cmd.ExecuteReader())
{ {
AssetMetadata metadata = new AssetMetadata(); while (dbReader.Read())
metadata.Name = (string)dbReader["Name"]; {
metadata.Description = (string)dbReader["Description"]; AssetMetadata metadata = new AssetMetadata();
metadata.Type = (sbyte)dbReader["AssetType"]; metadata.Name = (string)dbReader["Name"];
metadata.Temporary = Convert.ToBoolean(dbReader["Temporary"]); // Not sure if this is correct. metadata.Description = (string)dbReader["Description"];
metadata.Flags = (AssetFlags)Convert.ToInt32(dbReader["AssetFlags"]); metadata.Type = (sbyte)dbReader["AssetType"];
metadata.FullID = DBGuid.FromDB(dbReader["ID"]); metadata.Temporary = Convert.ToBoolean(dbReader["Temporary"]); // Not sure if this is correct.
metadata.CreatorID = dbReader["CreatorID"].ToString(); metadata.Flags = (AssetFlags)Convert.ToInt32(dbReader["AssetFlags"]);
metadata.FullID = DBGuid.FromDB(dbReader["ID"]);
metadata.CreatorID = dbReader["CreatorID"].ToString();
// We'll ignore this for now - it appears unused! // We'll ignore this for now - it appears unused!
// metadata.SHA1 = dbReader["hash"]); // metadata.SHA1 = dbReader["hash"]);
UpdateAccessTime(metadata, (int)dbReader["AccessTime"]); UpdateAccessTime(metadata, (int)dbReader["AccessTime"]);
retList.Add(metadata); retList.Add(metadata);
}
} }
} }
} catch (Exception e)
catch (Exception e) {
{ m_log.Error("[XASSETS DB]: MySql failure fetching asset set" + Environment.NewLine + e.ToString());
m_log.Error("[XASSETS DB]: MySql failure fetching asset set" + Environment.NewLine + e.ToString()); }
} }
} }

View File

@ -518,40 +518,42 @@ namespace OpenSim.Data.PGSQL
using (NpgsqlConnection dbcon = new NpgsqlConnection(m_connectionString)) using (NpgsqlConnection dbcon = new NpgsqlConnection(m_connectionString))
{ {
dbcon.Open(); dbcon.Open();
NpgsqlCommand cmd = new NpgsqlCommand( @"SELECT name, description, access_time, ""AssetType"", temporary, id, asset_flags, creatorid using(NpgsqlCommand cmd = new NpgsqlCommand(@"SELECT name, description, access_time, ""AssetType"", temporary, id, asset_flags, creatorid
FROM XAssetsMeta FROM XAssetsMeta
LIMIT :start, :count", dbcon); LIMIT :start, :count",dbcon))
cmd.Parameters.Add(m_database.CreateParameter("start", start));
cmd.Parameters.Add(m_database.CreateParameter("count", count));
try
{ {
using (NpgsqlDataReader dbReader = cmd.ExecuteReader()) cmd.Parameters.Add(m_database.CreateParameter("start",start));
cmd.Parameters.Add(m_database.CreateParameter("count", count));
try
{ {
while (dbReader.Read()) using (NpgsqlDataReader dbReader = cmd.ExecuteReader())
{ {
AssetMetadata metadata = new AssetMetadata(); while (dbReader.Read())
metadata.Name = (string)dbReader["name"]; {
metadata.Description = (string)dbReader["description"]; AssetMetadata metadata = new AssetMetadata();
metadata.Type = Convert.ToSByte(dbReader["AssetType"]); metadata.Name = (string)dbReader["name"];
metadata.Temporary = Convert.ToBoolean(dbReader["temporary"]); metadata.Description = (string)dbReader["description"];
metadata.Flags = (AssetFlags)Convert.ToInt32(dbReader["asset_flags"]); metadata.Type = Convert.ToSByte(dbReader["AssetType"]);
metadata.FullID = DBGuid.FromDB(dbReader["id"]); metadata.Temporary = Convert.ToBoolean(dbReader["temporary"]);
metadata.CreatorID = dbReader["creatorid"].ToString(); metadata.Flags = (AssetFlags)Convert.ToInt32(dbReader["asset_flags"]);
metadata.FullID = DBGuid.FromDB(dbReader["id"]);
metadata.CreatorID = dbReader["creatorid"].ToString();
// We'll ignore this for now - it appears unused! // We'll ignore this for now - it appears unused!
// metadata.SHA1 = dbReader["hash"]); // metadata.SHA1 = dbReader["hash"]);
UpdateAccessTime(metadata, (int)dbReader["access_time"]); UpdateAccessTime(metadata, (int)dbReader["access_time"]);
retList.Add(metadata); retList.Add(metadata);
}
} }
} }
} catch (Exception e)
catch (Exception e) {
{ m_log.Error("[XASSETS DB]: PGSql failure fetching asset set" + Environment.NewLine + e.ToString());
m_log.Error("[XASSETS DB]: PGSql failure fetching asset set" + Environment.NewLine + e.ToString()); }
} }
} }
} }