[gnome-system-monitor] -use std::string to not appear to be leaking memory. Close #566962
- From: Hubert Figuière <hub src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-system-monitor] -use std::string to not appear to be leaking memory. Close #566962
- Date: Sat, 18 Apr 2009 16:31:25 -0400 (EDT)
commit 4d3d18af7a588e50bc0a52ab30b020f1af2c8632
Author: Hubert Figuiere <hub figuiere net>
Date: Sat Apr 18 16:29:22 2009 -0400
-use std::string to not appear to be leaking memory. Close #566962
---
src/procman.h | 8 +++-----
src/proctable.cpp | 15 ++++++++-------
2 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/src/procman.h b/src/procman.h
index 9d51eee..c1171dd 100644
--- a/src/procman.h
+++ b/src/procman.h
@@ -96,12 +96,10 @@ struct ProcConfig
struct MutableProcInfo
{
MutableProcInfo()
- : user(0),
- status(0)
+ : status(0)
{ }
- // shared, don't free it !
- const gchar* user;
+ std::string user;
gchar wchan[40];
@@ -132,7 +130,7 @@ class ProcInfo
/* undefined */ ProcInfo& operator=(const ProcInfo&);
/* undefined */ ProcInfo(const ProcInfo&);
- typedef std::map<guint, const char*> UserMap;
+ typedef std::map<guint, std::string> UserMap;
/* cached username */
static UserMap users;
diff --git a/src/proctable.cpp b/src/proctable.cpp
index 557d116..a8f8ab9 100644
--- a/src/proctable.cpp
+++ b/src/proctable.cpp
@@ -24,6 +24,7 @@
#include <string.h>
#include <math.h>
#include <glib/gi18n.h>
+#include <glib/gprintf.h>
#include <glibtop.h>
#include <glibtop/loadavg.h>
#include <glibtop/proclist.h>
@@ -465,16 +466,16 @@ ProcInfo::set_user(guint uid)
// procman_debug("User lookup for uid %u: %s", uid, (p.second ? "MISS" : "HIT"));
if (p.second) {
- char* username;
struct passwd* pwd;
pwd = getpwuid(uid);
if (pwd && pwd->pw_name)
- username = g_strdup(pwd->pw_name);
- else
- username = g_strdup_printf("%u", uid);
-
- p.first->second = username;
+ p.first->second = pwd->pw_name;
+ else {
+ char username[16];
+ g_sprintf(username, "%u", uid);
+ p.first->second = username;
+ }
}
this->user = p.first->second;
@@ -543,7 +544,7 @@ update_info_mutable_cols(ProcInfo *info)
using procman::tree_store_update;
tree_store_update(model, &info->node, COL_STATUS, info->status);
- tree_store_update(model, &info->node, COL_USER, info->user);
+ tree_store_update(model, &info->node, COL_USER, info->user.c_str());
tree_store_update(model, &info->node, COL_VMSIZE, info->vmsize);
tree_store_update(model, &info->node, COL_MEMRES, info->memres);
tree_store_update(model, &info->node, COL_MEMWRITABLE, info->memwritable);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]