Print this page
3946 ::gcore
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>

@@ -18,11 +18,15 @@
  *
  * CDDL HEADER END
  */
 /*
  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
- *
+ */
+/*
+ * Copyright (c) 2013 by Delphix. All rights reserved.
+ */
+/*
  * Program to examine or set process privileges.
  */
 
 #include <stdio.h>
 #include <stdio_ext.h>

@@ -156,20 +160,18 @@
 }
 
 static int
 look(char *arg)
 {
-        static size_t pprivsz = sizeof (prpriv_t);
-        static prpriv_t *ppriv;
-
         struct ps_prochandle *Pr;
         int gcode;
         size_t sz;
         void *pdata;
         char *x;
         int i;
         boolean_t nodata;
+        prpriv_t *ppriv;
 
         procname = arg;         /* for perr() */
 
         if ((Pr = proc_arg_grab(arg, set ? PR_ARG_PIDS : PR_ARG_ANY,
             PGRAB_RETAIN | PGRAB_FORCE | (set ? 0 : PGRAB_RDONLY) |

@@ -177,19 +179,15 @@
                 (void) fprintf(stderr, "%s: cannot examine %s: %s\n",
                     command, arg, Pgrab_error(gcode));
                 return (1);
         }
 
-        if (ppriv == NULL)
-                ppriv = malloc(pprivsz);
-
-        if (Ppriv(Pr, ppriv, pprivsz) == -1) {
+        if (Ppriv(Pr, &ppriv) == -1) {
                 perr(command);
                 Prelease(Pr, 0);
                 return (1);
         }
-
         sz = PRIV_PRPRIV_SIZE(ppriv);
 
         /*
          * The ppriv fields are unsigned and may overflow, so check them
          * separately.  Size must be word aligned, so check that too.

@@ -200,32 +198,24 @@
             ppriv->pr_infosize > sz || sz > 1024 * 1024) {
                 (void) fprintf(stderr,
                     "%s: %s: bad PRNOTES section, size = %lx\n",
                     command, arg, (long)sz);
                 Prelease(Pr, 0);
+                free(ppriv);
                 return (1);
         }
 
-        if (sz > pprivsz) {
-                ppriv = realloc(ppriv, sz);
-
-                if (ppriv == NULL || Ppriv(Pr, ppriv, sz) != sz) {
-                        perr(command);
-                        Prelease(Pr, 0);
-                        return (1);
-                }
-                pprivsz = sz;
-        }
-
         if (set) {
                 privupdate(ppriv, arg);
                 if (Psetpriv(Pr, ppriv) != 0) {
                         perr(command);
                         Prelease(Pr, 0);
+                        free(ppriv);
                         return (1);
                 }
                 Prelease(Pr, 0);
+                free(ppriv);
                 return (0);
         }
 
         if (Pstate(Pr) == PS_DEAD) {
                 (void) printf("core '%s' of %d:\t%.70s\n",

@@ -296,10 +286,11 @@
                                 (void) printf("%08x", pc[j]);
                         (void) putchar('\n');
                 }
         }
         Prelease(Pr, 0);
+        free(ppriv);
         return (0);
 }
 
 static void
 fatal(const char *s)