Fix memory leaks
[platform/core/appfw/pkgmgr-info.git] / parser / src / pkgmgr_parser.c
index 52c8328..a71f6b1 100644 (file)
@@ -189,24 +189,30 @@ API int pkgmgr_parser_check_manifest_validation(const char *manifest)
        xschema = xmlSchemaParse(ctx);
        if (xschema == NULL) {
                _LOGE("xmlSchemaParse() Failed\n");
+               xmlSchemaFreeParserCtxt(ctx);
                return PMINFO_R_ERROR;
        }
        vctx = xmlSchemaNewValidCtxt(xschema);
        if (vctx == NULL) {
                _LOGE("xmlSchemaNewValidCtxt() Failed\n");
+               xmlSchemaFree(xschema);
+               xmlSchemaFreeParserCtxt(ctx);
                return PMINFO_R_ERROR;
        }
        xmlSchemaSetValidErrors(vctx, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stderr);
        ret = xmlSchemaValidateFile(vctx, manifest, 0);
        if (ret == -1) {
                _LOGE("xmlSchemaValidateFile() failed\n");
-               return PMINFO_R_ERROR;
+               ret = PMINFO_R_ERROR;
        } else if (ret == 0) {
                _LOGD("Manifest is Valid\n");
-               return PMINFO_R_OK;
+               ret = PMINFO_R_OK;
        } else {
                _LOGE("Manifest Validation Failed with error code %d\n", ret);
-               return PMINFO_R_ERROR;
+               ret = PMINFO_R_ERROR;
        }
-       return PMINFO_R_OK;
+       xmlSchemaFreeValidCtxt(vctx);
+       xmlSchemaFree(xschema);
+       xmlSchemaFreeParserCtxt(ctx);
+       return ret;
 }