harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From odea...@apache.org
Subject svn commit: r693826 - /harmony/enhanced/classlib/trunk/modules/print/src/main/native/print/windows/print.cpp
Date Wed, 10 Sep 2008 12:59:50 GMT
Author: odeakin
Date: Wed Sep 10 05:59:50 2008
New Revision: 693826

URL: http://svn.apache.org/viewvc?rev=693826&view=rev
Log:
Fix errors from HARMONY-5976 ([classlib] Results of static analysis):
 - Fix potential memory leak.
 - Use correct memory deallocator.

Modified:
    harmony/enhanced/classlib/trunk/modules/print/src/main/native/print/windows/print.cpp

Modified: harmony/enhanced/classlib/trunk/modules/print/src/main/native/print/windows/print.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/print/src/main/native/print/windows/print.cpp?rev=693826&r1=693825&r2=693826&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/print/src/main/native/print/windows/print.cpp
(original)
+++ harmony/enhanced/classlib/trunk/modules/print/src/main/native/print/windows/print.cpp
Wed Sep 10 05:59:50 2008
@@ -51,7 +51,7 @@
         return buffer;
     } else {
         if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
-            free(buffer);
+            delete[] buffer;
             buffer = new char[buffer_size];
             if (GetDefaultPrinter(buffer, &buffer_size)) {
                 return buffer;
@@ -108,7 +108,7 @@
     jstring service = NULL;
     if (serviceUTF != NULL) {
         service = env->NewStringUTF(serviceUTF);
-        free(serviceUTF);
+        delete[] serviceUTF;
     }
     return service;
 }
@@ -162,7 +162,7 @@
             }
         }
     }
-    free(editableName);
+    delete[] editableName;
     return result;
 }
 
@@ -372,7 +372,7 @@
                     env->DeleteLocalRef(jname);
                 }
             }
-            free(buffer);
+            delete[] buffer;
         }
         free(info);
     }
@@ -397,9 +397,9 @@
                     intIDs[i] = (int)ids[i];
                 }
                 env->SetIntArrayRegion(result, 0, numPapers, (jint *)intIDs);
-                free(intIDs);
+                delete[] intIDs;
             }
-            free(ids);
+            delete[] ids;
         }
         free(info);
     }
@@ -432,16 +432,16 @@
         int count = DeviceCapabilities(name, info->pPortName, DC_ENUMRESOLUTIONS, NULL,
NULL);
         if (count > 0) {
             LONG *nativeArray = new LONG[count * 2];
-            jint *intArray = new jint[count * 2];
             resolutions = env->NewIntArray(count * 2);
             if (DeviceCapabilities(name, info->pPortName, DC_ENUMRESOLUTIONS, (LPSTR)nativeArray,
NULL) > 0) {
+                jint *intArray = new jint[count * 2];
                 for (int i = 0; i < count * 2; i++) {
                     intArray[i] = (jint)((int)nativeArray[i]);
                 }
-                env->SetIntArrayRegion(resolutions, 0, count * 2, intArray);
-                free(nativeArray);
-                free(intArray);
+                env->SetIntArrayRegion(resolutions, 0, count * 2, intArray);     
+                delete[] intArray;
             }
+            delete[] nativeArray;
         }
         free(info);
     }



Mime
View raw message