Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 66404 invoked from network); 25 Jul 2007 20:38:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 25 Jul 2007 20:38:35 -0000 Received: (qmail 40276 invoked by uid 500); 25 Jul 2007 20:38:36 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 40186 invoked by uid 500); 25 Jul 2007 20:38:36 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 40175 invoked by uid 99); 25 Jul 2007 20:38:36 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 25 Jul 2007 13:38:36 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 25 Jul 2007 13:38:34 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 41B221A981A; Wed, 25 Jul 2007 13:38:14 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r559586 - /harmony/enhanced/drlvm/trunk/vm/port/src/vmem/linux/port_vmem.c Date: Wed, 25 Jul 2007 20:38:14 -0000 To: commits@harmony.apache.org From: gshimansky@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070725203814.41B221A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: gshimansky Date: Wed Jul 25 13:38:13 2007 New Revision: 559586 URL: http://svn.apache.org/viewvc?view=rev&rev=559586 Log: Applied additional patch from HARMONY-3427 to fix memory and handles leaks [drlvm][kernel][lang-management] MemoryMXBean native methods implementation Modified: harmony/enhanced/drlvm/trunk/vm/port/src/vmem/linux/port_vmem.c Modified: harmony/enhanced/drlvm/trunk/vm/port/src/vmem/linux/port_vmem.c URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/port/src/vmem/linux/port_vmem.c?view=diff&rev=559586&r1=559585&r2=559586 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/port/src/vmem/linux/port_vmem.c (original) +++ harmony/enhanced/drlvm/trunk/vm/port/src/vmem/linux/port_vmem.c Wed Jul 25 13:38:13 2007 @@ -145,52 +145,51 @@ APR_DECLARE(size_t) port_vmem_committed_size(){ char* buf = (char*) malloc(PATH_MAX + 1); - + size_t vmem = 0; pid_t my_pid = getpid(); + sprintf(buf, "/proc/%d/statm", my_pid); FILE* file = fopen(buf, "r"); if (!file) { - return 0; + goto cleanup; } size_t size = 0; ssize_t len = getline(&buf, &size, file); + fclose(file); if (len == -1) { - return 0; - } - size_t vmem; - int res = sscanf(buf, "%lu", &vmem); - if (res < 1) { - return 0; - } - if (buf) { - free(buf); + goto cleanup; } + sscanf(buf, "%lu", &vmem); + +cleanup: + free(buf); return vmem * port_vmem_page_sizes()[0]; } APR_DECLARE(size_t) port_vmem_max_size(){ char* buf = (char*) malloc(PATH_MAX + 1); + int pid, ppid, pgrp, session, tty_nr, tpgid, exit_signal, processor; + char comm[PATH_MAX]; + char state; + unsigned long flags, minflt, cminflt, majflt, cmajflt, utime, stime, + starttime, vsize, rlim = 0, startcode, endcode, startstack, kstkesp, + kstkeip, signal, blocked, sigignore, sigcatch, wchan, nswap, cnswap; + long cutime, cstime, priority, nice, unused, itrealvalue, rss; pid_t my_pid = getpid(); sprintf(buf, "/proc/%d/stat", my_pid); FILE* file = fopen(buf, "r"); if (!file) { - return 0; + goto cleanup; } size_t size = 0; ssize_t len = getline(&buf, &size, file); + fclose(file); if (len == -1) { - return 0; + goto cleanup; } - int pid, ppid, pgrp, session, tty_nr, tpgid, exit_signal, processor; - char comm[PATH_MAX]; - char state; - unsigned long flags, minflt, cminflt, majflt, cmajflt, utime, stime, - starttime, vsize, rlim, startcode, endcode, startstack, kstkesp, - kstkeip, signal, blocked, sigignore, sigcatch, wchan, nswap, cnswap; - long cutime, cstime, priority, nice, unused, itrealvalue, rss; - int res = sscanf(buf, "%d %s %c %d %d %d %d %d %lu %lu %lu %lu " + sscanf(buf, "%d %s %c %d %d %d %d %d %lu %lu %lu %lu " "%lu %lu %lu %ld %ld %ld %ld %ld %ld %lu %lu %ld %lu %lu %lu " "%lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %d %d", &pid, &comm, &state, &ppid, &pgrp, &session, &tty_nr, &tpgid, &flags, @@ -198,9 +197,9 @@ &priority, &nice, &unused, &itrealvalue, &starttime, &vsize, &rss, &rlim, &startcode, &endcode, &startstack, &kstkesp, &kstkeip, &signal, &blocked, &sigignore, &sigcatch, &wchan, &nswap, &cnswap, &exit_signal, &processor); - if (res < 25) { // rlim position - return 0; - }; + +cleanup: + free(buf); return rlim; }