]> granicus.if.org Git - icu/commitdiff
ICU-13380 Fixes for memory leaks & other problems found by Address Sanitizer.
authorAndy Heninger <andy.heninger@gmail.com>
Tue, 3 Oct 2017 04:11:26 +0000 (04:11 +0000)
committerAndy Heninger <andy.heninger@gmail.com>
Tue, 3 Oct 2017 04:11:26 +0000 (04:11 +0000)
X-SVN-Rev: 40529

icu4c/source/test/cintltst/cmsgtst.c
icu4c/source/test/cintltst/tracetst.c
icu4c/source/test/intltest/numfmtst.cpp
icu4c/source/tools/gendict/gendict.cpp
icu4c/source/tools/genrb/parse.cpp

index 8ed4969d6ccf8f079c80f0e9a47863bfa068c294..93ef88f1f3922cb3f3ae7072f204438f45a28807 100644 (file)
@@ -715,7 +715,7 @@ static void TestMsgFormatSelect(void)
         status=U_ZERO_ERROR;
         resultlength=resultLengthOut+1;
         result=(UChar*)malloc(sizeof(UChar) * resultlength);
-        u_formatMessage( "fr", pattern, u_strlen(pattern), result, resultlength, &status, str , str1);
+        u_formatMessage( "fr", pattern, u_strlen(pattern), result, resultlength, &status, str , str1, 6);
         if(u_strcmp(result, expected)==0)
             log_verbose("PASS: MessagFormat successful on Select test#2\n");
         else{
index 96e503127bb3923b3a180573307e8e6dcce2cec1..94d10046aebf1a964828a2e686371b5934585a8b 100644 (file)
@@ -339,7 +339,7 @@ static void TestTraceAPI() {
 
         /* Null ptrs for strings, vectors  */
         test_format("Null string - %s", 50, 0, "Null string - *NULL*", __LINE__, NULL);
-        test_format("Null string - %S", 50, 0, "Null string - *NULL*", __LINE__, NULL);
+        test_format("Null string - %S", 50, 0, "Null string - *NULL*", __LINE__, NULL, -1);
         test_format("Null vector - %vc", 50, 0, "Null vector - *NULL* [00000002]", __LINE__, NULL, 2);
         test_format("Null vector - %vC", 50, 0, "Null vector - *NULL* [00000002]", __LINE__, NULL, 2);
         test_format("Null vector - %vd", 50, 0, "Null vector - *NULL* [00000002]", __LINE__, NULL, 2);
index 09e3da1b8f4b8fc76837b758fb788a851f9d9b13..ce1432df2ebcda60f09d9c81dc7e3a95f29e666d 100644 (file)
@@ -2388,12 +2388,12 @@ void NumberFormatTest::TestCurrencyNames(void) {
 
 void NumberFormatTest::TestCurrencyUnit(void){
     UErrorCode ec = U_ZERO_ERROR;
-    static const UChar USD[] = {85, 83, 68, 0}; /*USD*/
-    static const char USD8[] = {85, 83, 68, 0};
-    static const UChar BAD[] = {63, 63, 63, 0}; /*???*/
-    static const UChar BAD2[] = {63, 63, 65, 0}; /*???*/
-    static const UChar XXX[] = u"XXX";
-    static const char XXX8[] = {88, 88, 88};
+    static const UChar USD[]  = u"USD";
+    static const char USD8[]  =  "USD";
+    static const UChar BAD[]  = u"???";
+    static const UChar BAD2[] = u"??A";
+    static const UChar XXX[]  = u"XXX";
+    static const char XXX8[]  =  "XXX";
     CurrencyUnit cu(USD, ec);
     assertSuccess("CurrencyUnit", ec);
 
@@ -8801,8 +8801,8 @@ void NumberFormatTest::Test13327_numberingSystemBufferOverflow() {
         assertSuccess("Constructing locale string", status);
         Locale locale(localeId.data());
 
-        NumberingSystem* ns = NumberingSystem::createInstance(locale, status);
-        assertFalse("Should not be null", ns == nullptr);
+        LocalPointer<NumberingSystem> ns(NumberingSystem::createInstance(locale, status));
+        assertFalse("Should not be null", ns.getAlias() == nullptr);
         assertSuccess("Should create with no error", status);
     }
 }
index 73b9fec32b8f2f2aeb0b5bc0a2acaa5715dc53bf..b712640091e5817b932dce3d87a293675486d066 100644 (file)
@@ -314,7 +314,7 @@ int  main(int argc, char **argv) {
     //  Read in the dictionary source file
     if (verbose) { printf("Opening file %s...\n", wordFileName); }
     const char *codepage = "UTF-8";
-    UCHARBUF *f = ucbuf_open(wordFileName, &codepage, TRUE, FALSE, status);
+    LocalUCHARBUFPointer f(ucbuf_open(wordFileName, &codepage, TRUE, FALSE, status));
     if (status.isFailure()) {
         fprintf(stderr, "error opening input file: ICU Error \"%s\"\n", status.errorName());
         exit(status.reset());
@@ -338,10 +338,10 @@ int  main(int argc, char **argv) {
     int minlen = 255;
     int maxlen = 0;
     UBool isOk = TRUE;
-    while (readLine(f, fileLine, status)) {
+    while (readLine(f.getAlias(), fileLine, status)) {
         lineCount++;
         if (fileLine.isEmpty()) continue;
-        
         // Parse word [spaces value].
         int32_t keyLen;
         for (keyLen = 0; keyLen < fileLine.length() && !u_isspace(fileLine[keyLen]); ++keyLen) {}
index 18f994dd2029ac6e31eb5105b2ef2b33c845c6f3..96ac4a7313b20c537f7e59a1828b706dfbd88b03 100644 (file)
@@ -763,8 +763,8 @@ GenrbImporter::getRules(
     }
 
     /* Parse the data into an SRBRoot */
-    struct SRBRoot *data =
-            parse(ucbuf.getAlias(), inputDir, outputDir, filename.data(), FALSE, FALSE, &errorCode);
+    LocalPointer<SRBRoot> data(
+            parse(ucbuf.getAlias(), inputDir, outputDir, filename.data(), FALSE, FALSE, &errorCode));
     if (U_FAILURE(errorCode)) {
         return;
     }