Fix even more leaks
[pandora-libraries.git] / lib / pnd_tinyxml.cpp
index 8bb7436..1aa8f9b 100644 (file)
@@ -225,9 +225,21 @@ unsigned char pnd_pxml_parse ( const char *pFilename, char *buffer, unsigned int
   // workaround for package ID's used by some package managers
   // get the package ID and store it for each application
   char* package_id = NULL;
+  char* package_version_major = NULL;
+  char* package_version_minor = NULL;
+  char* package_version_release = NULL;
+  char* package_version_build = NULL;
   pElem = hRoot.FirstChild ( PND_PXML_ENAME_PACKAGE ).Element();
   if ( pElem ) {
        package_id = pnd_pxml_get_attribute ( pElem, PND_PXML_ATTRNAME_PACKAGE_ID );
+   TiXmlHandle pRoot = TiXmlHandle( pElem );
+   if ( (pElem = pRoot.FirstChild(PND_PXML_ENAME_VERSION).Element()) )
+   {
+      package_version_major   = pnd_pxml_get_attribute(pElem, PND_PXML_ATTRNAME_VERMAJOR);
+      package_version_minor   = pnd_pxml_get_attribute(pElem, PND_PXML_ATTRNAME_VERMINOR);
+      package_version_release = pnd_pxml_get_attribute(pElem, PND_PXML_ATTRNAME_VERREL);
+      package_version_build   = pnd_pxml_get_attribute(pElem, PND_PXML_ATTRNAME_VERBUILD);
+   }
   }
 
   // move to applications element then
@@ -257,6 +269,14 @@ unsigned char pnd_pxml_parse ( const char *pFilename, char *buffer, unsigned int
     // give application the package id, if there is one
     if( package_id )
       app -> package_id               = strdup(package_id);
+    if( package_version_major )
+      app -> package_version_major    = strdup(package_version_major);
+    if( package_version_minor )
+      app -> package_version_minor    = strdup(package_version_minor);
+    if( package_version_release )
+      app -> package_version_release  = strdup(package_version_release);
+    if( package_version_build )
+      app -> package_version_build    = strdup(package_version_build);
 
     //Get unique ID first.
     if ( appwrappermode ) {
@@ -403,7 +423,13 @@ unsigned char pnd_pxml_parse ( const char *pFilename, char *buffer, unsigned int
        char *filetype = pnd_pxml_get_attribute(pElem, PND_PXML_ATTRNAME_ASSOCFTYPE);
        char *paramter = pnd_pxml_get_attribute(pElem, PND_PXML_ATTRNAME_ASSOCARGS);
 
-       if (!(name && filetype && paramter)) continue;
+       if (!(name && filetype && paramter))
+       {
+         if(name)     free(name);
+         if(filetype) free(filetype);
+         if(paramter) free(paramter);
+         continue;
+       }
 
        switch(i) //TODO: same problem here: only 3 associations supported
        {
@@ -428,6 +454,9 @@ unsigned char pnd_pxml_parse ( const char *pFilename, char *buffer, unsigned int
          app->associationitem3_parameter = paramter;
        }
        }
+       if(name)     free(name);
+       if(filetype) free(filetype);
+       if(paramter) free(paramter);
       }
     }
 
@@ -455,6 +484,7 @@ unsigned char pnd_pxml_parse ( const char *pFilename, char *buffer, unsigned int
        if ( ( t = pnd_pxml_get_attribute(pElem, PND_PXML_ATTRNAME_MKDIRPATH) ) ) {
          // first <dir>, so just replace it wholesale; we use strdup so we can free() easily later, consistently. Mmm, leak seems imminent.
          app -> mkdir_sp = strdup ( t );
+         free(t); // free this attribute
        }
 
        while ( ( pElem = pElem -> NextSiblingElement ( PND_PXML_ENAME_MKDIR ) ) ) {
@@ -468,6 +498,7 @@ unsigned char pnd_pxml_parse ( const char *pFilename, char *buffer, unsigned int
              app -> mkdir_sp = foo;
            } // assuming we got ram, lets cat it all together
 
+           free(t); // free this attribute
          } // got another elem?
 
        } // while
@@ -508,6 +539,14 @@ unsigned char pnd_pxml_parse ( const char *pFilename, char *buffer, unsigned int
 
   if( package_id )
      free(package_id);
+  if( package_version_major )
+     free(package_version_major);
+  if( package_version_minor )
+     free(package_version_minor);
+  if( package_version_release )
+     free(package_version_release);
+  if( package_version_build )
+     free(package_version_build);
 
   return (1);
 }