8025667: Warning from b62 for hotspot.agent.src.os.solaris.proc: use after free
authordsamersoff
Tue, 05 Aug 2014 06:11:35 -0700
changeset 25901 34036ccd1364
parent 25899 337ed0e9c13c
child 25902 7e9ffb1fe1df
8025667: Warning from b62 for hotspot.agent.src.os.solaris.proc: use after free Summary: move free call few lines down Reviewed-by: dholmes, sspitsyn
hotspot/agent/src/os/solaris/proc/saproc.cpp
--- a/hotspot/agent/src/os/solaris/proc/saproc.cpp	Sat Aug 02 16:28:59 2014 -0400
+++ b/hotspot/agent/src/os/solaris/proc/saproc.cpp	Tue Aug 05 06:11:35 2014 -0700
@@ -661,30 +661,30 @@
   // read FileMapHeader
   size_t n = read(fd, pheader, sizeof(struct FileMapHeader));
   if (n != sizeof(struct FileMapHeader)) {
-    free(pheader);
-    close(fd);
     char errMsg[ERR_MSG_SIZE];
     sprintf(errMsg, "unable to read shared archive file map header from %s", classes_jsa);
+    close(fd);
+    free(pheader);
     THROW_NEW_DEBUGGER_EXCEPTION_(errMsg, 1);
   }
 
   // check file magic
   if (pheader->_magic != 0xf00baba2) {
-    free(pheader);
-    close(fd);
     char errMsg[ERR_MSG_SIZE];
     sprintf(errMsg, "%s has bad shared archive magic 0x%x, expecting 0xf00baba2",
                    classes_jsa, pheader->_magic);
+    close(fd);
+    free(pheader);
     THROW_NEW_DEBUGGER_EXCEPTION_(errMsg, 1);
   }
 
   // check version
   if (pheader->_version != CURRENT_ARCHIVE_VERSION) {
-    free(pheader);
-    close(fd);
     char errMsg[ERR_MSG_SIZE];
     sprintf(errMsg, "%s has wrong shared archive version %d, expecting %d",
                    classes_jsa, pheader->_version, CURRENT_ARCHIVE_VERSION);
+    close(fd);
+    free(pheader);
     THROW_NEW_DEBUGGER_EXCEPTION_(errMsg, 1);
   }