[libbluray-devel] fixed leaks: Use cast instead of xmlStrdup() for string constants

hpi1 git at videolan.org
Fri Aug 17 12:53:24 CEST 2012


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Fri Aug 17 12:50:49 2012 +0300| [784772113b308e60aefec764babf6c7568b289e9] | committer: hpi1

fixed leaks: Use cast instead of xmlStrdup() for string constants

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=784772113b308e60aefec764babf6c7568b289e9
---

 src/libbluray/bdnav/meta_parse.c |   29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/src/libbluray/bdnav/meta_parse.c b/src/libbluray/bdnav/meta_parse.c
index 8a75145..313057d 100644
--- a/src/libbluray/bdnav/meta_parse.c
+++ b/src/libbluray/bdnav/meta_parse.c
@@ -43,6 +43,9 @@
 #include <libxml/tree.h>
 #endif
 
+#define BAD_CAST_CONST (const xmlChar *)
+
+
 #ifdef HAVE_LIBXML2
 static void _parseManifestNode(xmlNode * a_node, META_DL *disclib)
 {
@@ -50,37 +53,37 @@ static void _parseManifestNode(xmlNode * a_node, META_DL *disclib)
 
     for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
         if (cur_node->type == XML_ELEMENT_NODE) {
-            if (xmlStrEqual(cur_node->parent->name, xmlCharStrdup("title"))) {
-                if (xmlStrEqual(cur_node->name, xmlCharStrdup("name"))) {
+            if (xmlStrEqual(cur_node->parent->name, BAD_CAST_CONST "title")) {
+                if (xmlStrEqual(cur_node->name, BAD_CAST_CONST "name")) {
                     disclib->di_name = (char*)xmlStrdup(xmlNodeGetContent(cur_node));
                 }
-                if (xmlStrEqual(cur_node->name, xmlCharStrdup("alternative"))) {
+                if (xmlStrEqual(cur_node->name, BAD_CAST_CONST "alternative")) {
                     disclib->di_alternative = (char*)xmlStrdup(xmlNodeGetContent(cur_node));
                 }
-                if (xmlStrEqual(cur_node->name, xmlCharStrdup("numSets"))) {
+                if (xmlStrEqual(cur_node->name, BAD_CAST_CONST "numSets")) {
                     disclib->di_num_sets = atoi((char*)xmlNodeGetContent(cur_node));
                 }
-                if (xmlStrEqual(cur_node->name, xmlCharStrdup("setNumber"))) {
+                if (xmlStrEqual(cur_node->name, BAD_CAST_CONST "setNumber")) {
                     disclib->di_set_number = atoi((char*)xmlNodeGetContent(cur_node));
                 }
             }
-            else if (xmlStrEqual(cur_node->parent->name, xmlCharStrdup("tableOfContents"))) {
-                if (xmlStrEqual(cur_node->name, xmlCharStrdup("titleName")) && xmlGetProp(cur_node, xmlCharStrdup("titleNumber"))) {
+            else if (xmlStrEqual(cur_node->parent->name, BAD_CAST_CONST "tableOfContents")) {
+                if (xmlStrEqual(cur_node->name, BAD_CAST_CONST "titleName") && xmlGetProp(cur_node, BAD_CAST_CONST "titleNumber")) {
                     int i = disclib->toc_count;
                     disclib->toc_count++;
                     disclib->toc_entries = realloc(disclib->toc_entries, (disclib->toc_count*sizeof(META_TITLE)));
-                    disclib->toc_entries[i].title_number = atoi((const char*)xmlGetProp(cur_node, xmlCharStrdup("titleNumber")));
+                    disclib->toc_entries[i].title_number = atoi((const char*)xmlGetProp(cur_node, BAD_CAST_CONST "titleNumber"));
                     disclib->toc_entries[i].title_name = (char*)xmlStrdup(xmlNodeGetContent(cur_node));
                 }
             }
-            else if (xmlStrEqual(cur_node->parent->name, xmlCharStrdup("description"))) {
-                if (xmlStrEqual(cur_node->name, xmlCharStrdup("thumbnail")) && xmlGetProp(cur_node, xmlCharStrdup("href"))) {
+            else if (xmlStrEqual(cur_node->parent->name, BAD_CAST_CONST "description")) {
+                if (xmlStrEqual(cur_node->name, BAD_CAST_CONST "thumbnail") && xmlGetProp(cur_node, BAD_CAST_CONST "href")) {
                     uint8_t i = disclib->thumb_count;
                     disclib->thumb_count++;
                     disclib->thumbnails = realloc(disclib->thumbnails, (disclib->thumb_count*sizeof(META_THUMBNAIL)));
-                    disclib->thumbnails[i].path = strdup((const char*)xmlGetProp(cur_node, xmlCharStrdup("href")));
-                    if (xmlGetProp(cur_node, xmlCharStrdup("size"))) {
-                        sscanf((const char*)xmlGetProp(cur_node, xmlCharStrdup("size")), "%ix%i", &disclib->thumbnails[i].xres, &disclib->thumbnails[i].yres);
+                    disclib->thumbnails[i].path = strdup((const char*)xmlGetProp(cur_node, BAD_CAST_CONST "href"));
+                    if (xmlGetProp(cur_node, BAD_CAST_CONST "size")) {
+                        sscanf((const char*)xmlGetProp(cur_node, BAD_CAST_CONST "size"), "%ix%i", &disclib->thumbnails[i].xres, &disclib->thumbnails[i].yres);
                     }
                     else {
                         disclib->thumbnails[i].xres = disclib->thumbnails[i].yres = -1;



More information about the libbluray-devel mailing list