fixed: PeripheralTypeTranslator::IntToHexString() was leaking. thanks spiff
authorLars Op den Kamp <lars@opdenkamp.eu>
Wed, 19 Oct 2011 19:22:50 +0000 (21:22 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Wed, 19 Oct 2011 19:22:50 +0000 (21:22 +0200)
xbmc/peripherals/PeripheralTypes.h
xbmc/peripherals/Peripherals.cpp
xbmc/peripherals/devices/Peripheral.cpp
xbmc/peripherals/devices/Peripheral.h
xbmc/peripherals/devices/PeripheralHID.cpp

index 9323325..f3f0bf4 100644 (file)
@@ -155,16 +155,14 @@ namespace PERIPHERALS
       return iVal;
     };
 
-    static char *IntToHexString(int iVal)
+    static void FormatHexString(int iVal, CStdString &strHexString)
     {
       if (iVal < 0)
         iVal = 0;
       if (iVal > 65536)
         iVal = 65536;
 
-      char *buf = new char[4];
-      sprintf(buf, "%04X", iVal);
-      return buf;
+      strHexString.Format("%04X", iVal);
     };
   };
 }
index e9d84be..528d2ea 100644 (file)
@@ -324,7 +324,10 @@ int CPeripherals::GetMappingForDevice(const CPeripheralBus &bus, const Periphera
 
     if (bBusMatch && bVendorMatch && bProductMatch && bClassMatch)
     {
-      CLog::Log(LOGDEBUG, "%s - device (%s:%s) mapped to %s (type = %s)", __FUNCTION__, PeripheralTypeTranslator::IntToHexString(iVendorId), PeripheralTypeTranslator::IntToHexString(iProductId), mapping.m_strDeviceName.c_str(), PeripheralTypeTranslator::TypeToString(mapping.m_mappedTo));
+      CStdString strVendorId, strProductId;
+      PeripheralTypeTranslator::FormatHexString(iVendorId, strVendorId);
+      PeripheralTypeTranslator::FormatHexString(iProductId, strProductId);
+      CLog::Log(LOGDEBUG, "%s - device (%s:%s) mapped to %s (type = %s)", __FUNCTION__, strVendorId.c_str(), strProductId.c_str(), mapping.m_strDeviceName.c_str(), PeripheralTypeTranslator::TypeToString(mapping.m_mappedTo));
       return iMappingPtr;
     }
   }
index 27ab0a4..cc046dc 100644 (file)
@@ -37,13 +37,13 @@ CPeripheral::CPeripheral(const PeripheralType type, const PeripheralBusType busT
   m_strDeviceName(strDeviceName),
   m_strFileLocation(StringUtils::EmptyString),
   m_iVendorId(iVendorId),
-  m_strVendorId(PeripheralTypeTranslator::IntToHexString(iVendorId)),
   m_iProductId(iProductId),
-  m_strProductId(PeripheralTypeTranslator::IntToHexString(iProductId)),
   m_bInitialised(false),
   m_bHidden(false),
   m_bError(false)
 {
+  PeripheralTypeTranslator::FormatHexString(iVendorId, m_strVendorId);
+  PeripheralTypeTranslator::FormatHexString(iProductId, m_strProductId);
   m_strFileLocation.Format("peripherals://%s/%s.dev", PeripheralTypeTranslator::BusTypeToString(busType), strLocation.c_str());
 }
 
@@ -54,9 +54,9 @@ CPeripheral::CPeripheral(void) :
   m_strDeviceName(StringUtils::EmptyString),
   m_strFileLocation(StringUtils::EmptyString),
   m_iVendorId(0),
-  m_strVendorId(PeripheralTypeTranslator::IntToHexString(0)),
+  m_strVendorId("0000"),
   m_iProductId(0),
-  m_strProductId(PeripheralTypeTranslator::IntToHexString(0)),
+  m_strProductId("0000"),
   m_bInitialised(false),
   m_bHidden(false)
 {
@@ -135,7 +135,7 @@ bool CPeripheral::Initialise(void)
     return bReturn;
 
   g_peripherals.GetSettingsFromMapping(*this);
-  m_strSettingsFile.Format("special://profile/peripheral_data/%s_%s_%s.xml", PeripheralTypeTranslator::BusTypeToString(m_busType), m_strVendorId, m_strProductId);
+  m_strSettingsFile.Format("special://profile/peripheral_data/%s_%s_%s.xml", PeripheralTypeTranslator::BusTypeToString(m_busType), m_strVendorId.c_str(), m_strProductId.c_str());
   LoadPersistedSettings();
 
   for (unsigned int iFeaturePtr = 0; iFeaturePtr < m_features.size(); iFeaturePtr++)
index 559a561..e7860e4 100644 (file)
@@ -45,9 +45,9 @@ namespace PERIPHERALS
     const CStdString &FileLocation(void) const     { return m_strFileLocation; }
     const CStdString &Location(void) const         { return m_strLocation; }
     int VendorId(void) const                       { return m_iVendorId; }
-    const char *VendorIdAsString(void) const       { return m_strVendorId; }
+    const char *VendorIdAsString(void) const       { return m_strVendorId.c_str(); }
     int ProductId(void) const                      { return m_iProductId; }
-    const char *ProductIdAsString(void) const      { return m_strProductId; }
+    const char *ProductIdAsString(void) const      { return m_strProductId.c_str(); }
     const PeripheralType Type(void) const          { return m_type; }
     const PeripheralBusType GetBusType(void) const { return m_busType; };
     const CStdString &DeviceName(void) const       { return m_strDeviceName; }
@@ -159,9 +159,9 @@ namespace PERIPHERALS
     CStdString                       m_strSettingsFile;
     CStdString                       m_strFileLocation;
     int                              m_iVendorId;
-    char *                           m_strVendorId;
+    CStdString                       m_strVendorId;
     int                              m_iProductId;
-    char *                           m_strProductId;
+    CStdString                       m_strProductId;
     bool                             m_bInitialised;
     bool                             m_bHidden;
     bool                             m_bError;
index da590d5..7917bd7 100644 (file)
@@ -73,7 +73,7 @@ bool CPeripheralHID::InitialiseFeature(const PeripheralFeature feature)
       }
     }
 
-    CLog::Log(LOGDEBUG, "%s - initialised HID device (%s:%s)", __FUNCTION__, m_strVendorId, m_strProductId);
+    CLog::Log(LOGDEBUG, "%s - initialised HID device (%s:%s)", __FUNCTION__, m_strVendorId.c_str(), m_strProductId.c_str());
   }
 
   return CPeripheral::InitialiseFeature(feature);