From 27ed2708514593796cde83e4518964fd87f97265 Mon Sep 17 00:00:00 2001 From: albert <> Date: Tue, 11 Feb 2003 08:19:12 +0000 Subject: [PATCH] memory leak fixed --- NEWS | 1 + proc/procps.h | 63 ++++++++++++++++++++++++++----------------------- proc/readproc.h | 1 - top.c | 7 +++--- 4 files changed, 38 insertions(+), 34 deletions(-) diff --git a/NEWS b/NEWS index 0d69cc7b..599506c9 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,6 @@ procps-3.1.5 --> procps-3.1.6 +top: memory leak fixed ps: new --ppid option selects by PPID watch: new --no-title option handle SPARC Linux badness diff --git a/proc/procps.h b/proc/procps.h index 605144f5..95134a6b 100644 --- a/proc/procps.h +++ b/proc/procps.h @@ -34,8 +34,12 @@ #define STRTOUKL strtoul #endif +// since gcc-2.5 +#define NORETURN __attribute__((__noreturn__)) +#define FUNCTION __attribute__((__const__)) // no access to global mem, even via ptr, and no side effect + #if !defined(restrict) && __STDC_VERSION__ < 199901 -#if __GNUC__ > 2 || __GNUC_MINOR__ >= 92 // maybe 92 or 95 ? +#if __GNUC__ > 2 || __GNUC_MINOR__ >= 92 #define restrict __restrict__ #else #warning No restrict keyword? @@ -43,35 +47,6 @@ #endif #endif -// marks old junk, to warn non-procps library users -#if ( __GNUC__ == 3 && __GNUC_MINOR__ > 0 ) || __GNUC__ > 3 -#define OBSOLETE __attribute__((deprecated)) -#else -#define OBSOLETE -#endif - -// Tells gcc that function is library-internal; -// so no need to do dynamic linking at run-time. -// This might work with slightly older compilers too. -#if ( __GNUC__ == 3 && __GNUC_MINOR__ > 1 ) || __GNUC__ > 3 -#define HIDDEN __attribute__((visibility("hidden"))) -#else -#define HIDDEN -#endif - -// Like HIDDEN, but for an alias that gets created. -// In gcc-3.2 there is an alias+hidden conflict. -// Many will have patched this bug, but oh well. -#if ( __GNUC__ == 3 && __GNUC_MINOR__ > 2 ) || __GNUC__ > 3 -#define HIDDEN_ALIAS(x) extern __typeof(x) x##_direct __attribute__((alias(#x),visibility("hidden"))) -#else -#define HIDDEN_ALIAS(x) extern __typeof(x) x##_direct __attribute__((alias(#x))) -#endif - -// since gcc-2.5 -#define NORETURN __attribute__((__noreturn__)) -#define FUNCTION __attribute__((__const__)) // no access to global mem, even via ptr, and no side effect - #if __GNUC__ > 2 || __GNUC_MINOR__ >= 96 // won't alias anything, and aligned enough for anything #define MALLOC __attribute__ ((__malloc__)) @@ -89,4 +64,32 @@ #define expected(x,y) (x) #endif +// marks old junk, to warn non-procps library users +#if ( __GNUC__ == 3 && __GNUC_MINOR__ > 0 ) || __GNUC__ > 3 +#define OBSOLETE __attribute__((deprecated)) +#else +#define OBSOLETE +#endif + +#if ( __GNUC__ == 3 && __GNUC_MINOR__ > 1 ) || __GNUC__ > 3 +// Tells gcc that function is library-internal; +// so no need to do dynamic linking at run-time. +// This might work with slightly older compilers too. +#define HIDDEN __attribute__((visibility("hidden"))) +// Tell g++ that a function won't throw exceptions. +#define NOTHROW __attribute__((__nothrow__)) +#else +#define HIDDEN +#define NOTHROW +#endif + +// Like HIDDEN, but for an alias that gets created. +// In gcc-3.2 there is an alias+hidden conflict. +// Many will have patched this bug, but oh well. +#if ( __GNUC__ == 3 && __GNUC_MINOR__ > 2 ) || __GNUC__ > 3 +#define HIDDEN_ALIAS(x) extern __typeof(x) x##_direct __attribute__((alias(#x),visibility("hidden"))) +#else +#define HIDDEN_ALIAS(x) extern __typeof(x) x##_direct __attribute__((alias(#x))) +#endif + #endif diff --git a/proc/readproc.h b/proc/readproc.h index 5ddba15b..88fe7756 100644 --- a/proc/readproc.h +++ b/proc/readproc.h @@ -212,7 +212,6 @@ extern void freeproc(proc_t* p); #define PROC_FILLWCHAN 0x0080 /* look up WCHAN name */ #define PROC_FILLARG 0x0100 /* alloc and fill in `cmdline' */ -#define PROC_FILLBUG 0x0fff /* No idea what we need */ #define PROC_FILLANY 0x0000 /* either stat or status will do */ /* Obsolete, consider only processes with one of the passed: */ diff --git a/top.c b/top.c index f19fee3e..a3b7cb1e 100644 --- a/top.c +++ b/top.c @@ -1021,7 +1021,7 @@ static proc_t **procs_refresh (proc_t **table, int flags) prochlp(NULL); // prep for a new frame if (Monpidsidx) - PT = openproc(PROC_FILLBUG | PROC_PID, Monpids); + PT = openproc(flags, Monpids); else PT = openproc(flags); @@ -2096,6 +2096,7 @@ static void reframewins (void) if (!(Frames_libflags & L_stat)) Frames_libflags |= L_status; } if (!Frames_libflags) Frames_libflags = L_DEFAULT; + if (selection_type=='p') Frames_libflags |= PROC_PID; } @@ -2801,7 +2802,7 @@ static proc_t **summary_show (void) // whoa first time, gotta' prime the pump... if (!p_table) { - p_table = procs_refresh(NULL, L_DEFAULT); + p_table = procs_refresh(NULL, Frames_libflags); putp(Cap_clr_scr); sleep(1); } else @@ -3141,7 +3142,7 @@ static void frame_make (void) proc_t **ppt; int i, scrlins; - /* note: except for PROC_PID, all libproc flags are managed by + /* note: all libproc flags are managed by reframewins(), who also builds each window's column headers */ if (!Frames_libflags) { reframewins();