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;
}
MySqlCommand cmd = conn.CreateCommand();
cmd.CommandText = String.Format("select count(*) as count from {0}", m_Table);
using (IDataReader reader = cmd.ExecuteReader())
using(MySqlCommand cmd = conn.CreateCommand())
{
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)
{
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);
cmd.Dispose();
ExecuteNonQuery(cmd);
}
return true;
}

View File

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