From ntarmos@ceid.upatras.gr  Mon Jul  9 12:06:04 2007
Return-Path: <ntarmos@ceid.upatras.gr>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 1855116A421
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  9 Jul 2007 12:06:04 +0000 (UTC)
	(envelope-from ntarmos@ceid.upatras.gr)
Received: from poseidon.ceid.upatras.gr (poseidon.ceid.upatras.gr [150.140.141.169])
	by mx1.freebsd.org (Postfix) with ESMTP id 8EF5513C44B
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  9 Jul 2007 12:06:03 +0000 (UTC)
	(envelope-from ntarmos@ceid.upatras.gr)
Received: from mail.ceid.upatras.gr (unknown [10.1.0.143])
	by poseidon.ceid.upatras.gr (Postfix) with ESMTP id C0610EB47EF
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  9 Jul 2007 15:05:59 +0300 (EEST)
Received: from localhost (europa.ceid.upatras.gr [127.0.0.1])
	by mail.ceid.upatras.gr (Postfix) with ESMTP id A099C2B9A283
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  9 Jul 2007 15:05:59 +0300 (EEST)
Received: from mail.ceid.upatras.gr ([127.0.0.1])
	by localhost (europa.ceid.upatras.gr [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id p9HkGZkT-xOY for <FreeBSD-gnats-submit@freebsd.org>;
	Mon,  9 Jul 2007 15:05:59 +0300 (EEST)
Received: from ace.b020.ceid.upatras.gr (csisgroup13.ceid.upatras.gr [150.140.143.227])
	by mail.ceid.upatras.gr (Postfix) with ESMTP id 4A0342B9A286
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  9 Jul 2007 15:05:59 +0300 (EEST)
Received: by ace.b020.ceid.upatras.gr (Postfix, from userid 1001)
	id 3685D3F40B; Mon,  9 Jul 2007 15:05:57 +0300 (EEST)
Message-Id: <20070709120557.3685D3F40B@ace.b020.ceid.upatras.gr>
Date: Mon,  9 Jul 2007 15:05:57 +0300 (EEST)
From: Nikos Ntarmos <ntarmos@ceid.upatras.gr>
Reply-To: Nikos Ntarmos <ntarmos@ceid.upatras.gr>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [patch] sysutils/conky dumps core with less than 10 processes in top
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         114437
>Category:       ports
>Synopsis:       [patch] sysutils/conky dumps core with less than 10 processes in top
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    novel
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jul 09 12:10:13 GMT 2007
>Closed-Date:    Mon Aug 20 06:55:19 GMT 2007
>Last-Modified:  Mon Aug 20 06:55:19 GMT 2007
>Originator:     Nikos Ntarmos
>Release:        FreeBSD 7.0-CURRENT i386
>Organization:
NetCInS Lab., C.E.I.D., U. of Patras, Greece
>Environment:
System: FreeBSD ace.b020.ceid.upatras.gr 7.0-CURRENT FreeBSD 7.0-CURRENT #3: Sun Jul 8 19:13:50 EEST 2007 ntarmos@ace.b020.ceid.upatras.gr:/opt/obj/opt/src/sys/ACE i386


	
>Description:
src/freebsd.c:proc_find_top() incorrectly assumes that at each point
there are at least 10 processes running. This may easily be false if
security.bsd.see_other_uids=0 and/or conky is launched early enough in
the xsession script.

	
>How-To-Repeat:
Set security.bsd.see_other_uids=0 and launch conky early in the xsession
script (or with less than 9 other processes running).
	
>Fix:

	

--- patch-src-freebsd.c-nprocsmax begins here ---
diff -u src/freebsd.c.orig src/freebsd.c
--- src/freebsd.c.orig	2007-07-09 13:13:14.000000000 +0300
+++ src/freebsd.c	2007-07-07 01:31:17.000000000 +0300
@@ -714,6 +714,7 @@
 	int n_processes;
 	int i, j = 0;
 	struct process *processes;
+	int nprocsmax;
 
 	int total_pages;
 
@@ -738,8 +739,10 @@
 		}
 	}
 
+	nprocsmax = (j > 10 ? 10 : j);
+
 	qsort(processes, j - 1, sizeof (struct process), comparemem);
-	for (i = 0; i < 10; i++) {
+	for (i = 0; i < nprocsmax; i++) {
 		struct process *tmp, *ttmp;
 
 		tmp = malloc(sizeof (struct process));
@@ -757,7 +760,7 @@
 	}
 
 	qsort(processes, j - 1, sizeof (struct process), comparecpu);
-	for (i = 0; i < 10; i++) {
+	for (i = 0; i < nprocsmax; i++) {
 		struct process *tmp, *ttmp;
 
 		tmp = malloc(sizeof (struct process));
@@ -776,13 +779,13 @@
 
 #if defined(FREEBSD_DEBUG)
 	printf("=====\nmem\n");
-	for (i = 0; i < 10; i++) {
+	for (i = 0; i < nprocsmax; i++) {
 		printf("%d: %s(%d) %.2f\n", i, mem[i]->name,
 				mem[i]->pid, mem[i]->totalmem);
 	}
 #endif
 
-	for (i = 0; i < j; free(processes[i++].name));
+	for (i = 0; i < nprocsmax; free(processes[i++].name));
 	free(processes);
 }
 
--- patch-src-freebsd.c-nprocsmax ends here ---


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->novel 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Mon Jul 9 12:10:20 UTC 2007 
Responsible-Changed-Why:  
Over to maintainer 

http://www.freebsd.org/cgi/query-pr.cgi?pr=114437 

From: Nikos Ntarmos <ntarmos@ceid.upatras.gr>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/114437: [patch] sysutils/conky dumps core with less than 10 processes in top
Date: Thu, 12 Jul 2007 04:13:29 +0300

 --BXVAT5kNtrzKuDFl
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 The last changeline in the previous patch was wrong (subtle memory
 leak). Fixed patch attached.
 
 
 --BXVAT5kNtrzKuDFl
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename="patch-src-freebsd.c-nprocsmax"
 
 diff -u src/freebsd.c.orig src/freebsd.c
 --- src/freebsd.c.orig	2007-07-09 13:13:14.000000000 +0300
 +++ src/freebsd.c	2007-07-07 01:31:17.000000000 +0300
 @@ -714,6 +714,7 @@
  	int n_processes;
  	int i, j = 0;
  	struct process *processes;
 +	int nprocsmax;
  
  	int total_pages;
  
 @@ -723,7 +724,7 @@
  			"\"vm.stats.vm.v_page_count\"");
  
  	p = kvm_getprocs(kd, KERN_PROC_PROC, 0, &n_processes);
 -	processes = malloc(n_processes * sizeof (struct process));
 +	processes = calloc(n_processes, sizeof (struct process));
  
  	for (i = 0; i < n_processes; i++) {
  		if (!((p[i].ki_flag & P_SYSTEM)) &&
 @@ -738,8 +739,10 @@
  		}
  	}
  
 +	nprocsmax = (j > 10 ? 10 : j);
 +
  	qsort(processes, j - 1, sizeof (struct process), comparemem);
 -	for (i = 0; i < 10; i++) {
 +	for (i = 0; i < nprocsmax; i++) {
  		struct process *tmp, *ttmp;
  
  		tmp = malloc(sizeof (struct process));
 @@ -757,7 +760,7 @@
  	}
  
  	qsort(processes, j - 1, sizeof (struct process), comparecpu);
 -	for (i = 0; i < 10; i++) {
 +	for (i = 0; i < nprocsmax; i++) {
  		struct process *tmp, *ttmp;
  
  		tmp = malloc(sizeof (struct process));
 @@ -776,7 +779,7 @@
  
  #if defined(FREEBSD_DEBUG)
  	printf("=====\nmem\n");
 -	for (i = 0; i < 10; i++) {
 +	for (i = 0; i < nprocsmax; i++) {
  		printf("%d: %s(%d) %.2f\n", i, mem[i]->name,
  				mem[i]->pid, mem[i]->totalmem);
  	}
 
 --BXVAT5kNtrzKuDFl--
State-Changed-From-To: open->closed 
State-Changed-By: novel 
State-Changed-When: Mon Aug 20 06:55:11 UTC 2007 
State-Changed-Why:  
Fixed in 1.4.6. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=114437 
>Unformatted:
