]> granicus.if.org Git - icu/commitdiff
ICU-10331 Fix memory leak in data test
authorMichael Ow <mow@svn.icu-project.org>
Tue, 10 Sep 2013 17:03:42 +0000 (17:03 +0000)
committerMichael Ow <mow@svn.icu-project.org>
Tue, 10 Sep 2013 17:03:42 +0000 (17:03 +0000)
X-SVN-Rev: 34260

icu4c/source/test/cintltst/udatatst.c

index 09aef10030a5aadcb09cd4a38981528c5d732696..70c4f66baa1179b428fda370f4e582a21c17c692 100644 (file)
@@ -156,32 +156,33 @@ static void TestUDataOpen(){
        *   If packaging mode == dll, the file may not exist.  So, if the file is 
        *   missing, skip this test without error.
        */
-      icuDataFilePath = (char *)malloc(strlen(path) + 10);
+      icuDataFilePath = (char *)uprv_malloc(strlen(path) + 10);
       strcpy(icuDataFilePath, path);
       strcat(icuDataFilePath, ".dat");
       /* lots_of_mallocs(); */
       if (uprv_fileExists(icuDataFilePath))
-       {
-         int i;
-         log_verbose("Testing udata_open() on %s\n", icuDataFilePath);
-         for(i=0; i<sizeof(memMap)/sizeof(memMap[0]); i++){
+      {
+          int i;
+          log_verbose("Testing udata_open() on %s\n", icuDataFilePath);
+          for(i=0; i<sizeof(memMap)/sizeof(memMap[0]); i++){
             /* lots_of_mallocs(); */
             status=U_ZERO_ERROR;
             result=udata_open(path, memMap[i][1], memMap[i][0], &status);
             if(U_FAILURE(status)) {
-             log_data_err("FAIL: udata_open() failed for path = %s, name=%s, type=%s, \n errorcode=%s\n", path, memMap[i][0], memMap[i][1], myErrorName(status));
+                log_data_err("FAIL: udata_open() failed for path = %s, name=%s, type=%s, \n errorcode=%s\n", path, memMap[i][0], memMap[i][1], myErrorName(status));
             } else {
-             log_verbose("PASS: udata_open worked for path = %s, name=%s, type=%s\n",  path, memMap[i][0], memMap[i][1]);
-             udata_close(result);
+                log_verbose("PASS: udata_open worked for path = %s, name=%s, type=%s\n",  path, memMap[i][0], memMap[i][1]);
+                udata_close(result);
             }
-         }
-       }
+          }
+      }
       else
-       {
-         /* lots_of_mallocs(); */
-         log_verbose("Skipping tests of udata_open() on %s.  File not present in this configuration.\n",
-                     icuDataFilePath);
-       }
+      {
+          /* lots_of_mallocs(); */
+          log_verbose("Skipping tests of udata_open() on %s.  File not present in this configuration.\n",
+                  icuDataFilePath);
+      }
+      uprv_free(icuDataFilePath);
     }
     /* try again, adding /tmp */
     {