changeset 12283:a71b53580d07

8169344: Potential open file descriptor in exists() of hotspot/agent/src/os/bsd/ps_core.c Summary: Use access() instead of open() to check for the existence of a file Reviewed-by: dsamersoff, dholmes Contributed-by: jini.george@oracle.com
author dsamersoff
date Wed, 09 Nov 2016 10:56:32 +0300
parents a169535aff9d
children 8e5e93fad474
files src/jdk.hotspot.agent/macosx/native/libsaproc/ps_core.c
diffstat 1 files changed, 3 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.hotspot.agent/macosx/native/libsaproc/ps_core.c	Wed Nov 09 09:30:27 2016 +0300
+++ b/src/jdk.hotspot.agent/macosx/native/libsaproc/ps_core.c	Wed Nov 09 10:56:32 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -697,14 +697,8 @@
 }
 
 /**local function **/
-bool exists(const char *fname)
-{
-  int fd;
-  if ((fd = open(fname, O_RDONLY)) > 0) {
-    close(fd);
-    return true;
-  }
-  return false;
+bool exists(const char *fname) {
+  return access(fname, F_OK) == 0;
 }
 
 // we check: 1. lib