[haiku-commits] haiku: hrev53242 - src/system/kernel

  • From: waddlesplash <waddlesplash@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 11 Jul 2019 22:00:51 -0400 (EDT)

hrev53242 adds 1 changeset to branch 'master'
old head: 0e6ece91c81de4bb1056c4743c09d40d6106c4a1
new head: f4e3bb1cc668e93c443d461d562eaa7526cc2f45
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=f4e3bb1cc668+%5E0e6ece91c81d

----------------------------------------------------------------------------

f4e3bb1cc668: kernel/team: Avoid allocating memory in 
_user_get_extended_team_info.
  
  Terminal calls this multiple times a second per open tab, so it
  was spamming up my malloc logs. I don't see any reason this 60-byte
  structure needs to be on the heap; so, leave it on the stack instead.
  
  Change-Id: I3f1ac14fe9bfec39cd0d5668c68f84467450b0c0
  Reviewed-on: https://review.haiku-os.org/c/1580
  Reviewed-by: Adrien Destugues <pulkomandy@xxxxxxxxx>

                              [ Augustin Cavalier <waddlesplash@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev53242
Commit:      f4e3bb1cc668e93c443d461d562eaa7526cc2f45
URL:         https://git.haiku-os.org/haiku/commit/?id=f4e3bb1cc668
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Thu Jul 11 03:22:01 2019 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Fri Jul 12 02:00:47 2019 UTC

----------------------------------------------------------------------------

1 file changed, 17 insertions(+), 26 deletions(-)
src/system/kernel/team.cpp | 43 +++++++++++++++++-------------------------

----------------------------------------------------------------------------

diff --git a/src/system/kernel/team.cpp b/src/system/kernel/team.cpp
index 25be5c40c0..e5f159de18 100644
--- a/src/system/kernel/team.cpp
+++ b/src/system/kernel/team.cpp
@@ -4401,16 +4401,7 @@ _user_get_extended_team_info(team_id teamID, uint32 
flags, void* buffer,
                        uid_t   effective_uid;
                        gid_t   effective_gid;
                        char    name[B_OS_NAME_LENGTH];
-               };
-
-               ExtendedTeamData* teamClone
-                       = (ExtendedTeamData*)malloc(sizeof(ExtendedTeamData));
-                       // It would be nicer to use new, but then we'd have to 
use
-                       // ObjectDeleter and declare the structure outside of 
the function
-                       // due to template parameter restrictions.
-               if (teamClone == NULL)
-                       return B_NO_MEMORY;
-               MemoryDeleter teamCloneDeleter(teamClone);
+               } teamClone;
 
                io_context* ioContext;
                {
@@ -4422,14 +4413,14 @@ _user_get_extended_team_info(team_id teamID, uint32 
flags, void* buffer,
                        TeamLocker teamLocker(team, true);
 
                        // copy the data
-                       teamClone->id = team->id;
-                       strlcpy(teamClone->name, team->Name(), 
sizeof(teamClone->name));
-                       teamClone->group_id = team->group_id;
-                       teamClone->session_id = team->session_id;
-                       teamClone->real_uid = team->real_uid;
-                       teamClone->real_gid = team->real_gid;
-                       teamClone->effective_uid = team->effective_uid;
-                       teamClone->effective_gid = team->effective_gid;
+                       teamClone.id = team->id;
+                       strlcpy(teamClone.name, team->Name(), 
sizeof(teamClone.name));
+                       teamClone.group_id = team->group_id;
+                       teamClone.session_id = team->session_id;
+                       teamClone.real_uid = team->real_uid;
+                       teamClone.real_gid = team->real_gid;
+                       teamClone.effective_uid = team->effective_uid;
+                       teamClone.effective_gid = team->effective_gid;
 
                        // also fetch a reference to the I/O context
                        ioContext = team->io_context;
@@ -4439,14 +4430,14 @@ _user_get_extended_team_info(team_id teamID, uint32 
flags, void* buffer,
                        &vfs_put_io_context);
 
                // add the basic data to the info message
-               if (info.AddInt32("id", teamClone->id) != B_OK
-                       || info.AddString("name", teamClone->name) != B_OK
-                       || info.AddInt32("process group", teamClone->group_id) 
!= B_OK
-                       || info.AddInt32("session", teamClone->session_id) != 
B_OK
-                       || info.AddInt32("uid", teamClone->real_uid) != B_OK
-                       || info.AddInt32("gid", teamClone->real_gid) != B_OK
-                       || info.AddInt32("euid", teamClone->effective_uid) != 
B_OK
-                       || info.AddInt32("egid", teamClone->effective_gid) != 
B_OK) {
+               if (info.AddInt32("id", teamClone.id) != B_OK
+                       || info.AddString("name", teamClone.name) != B_OK
+                       || info.AddInt32("process group", teamClone.group_id) 
!= B_OK
+                       || info.AddInt32("session", teamClone.session_id) != 
B_OK
+                       || info.AddInt32("uid", teamClone.real_uid) != B_OK
+                       || info.AddInt32("gid", teamClone.real_gid) != B_OK
+                       || info.AddInt32("euid", teamClone.effective_uid) != 
B_OK
+                       || info.AddInt32("egid", teamClone.effective_gid) != 
B_OK) {
                        return B_NO_MEMORY;
                }
 


Other related posts:

  • » [haiku-commits] haiku: hrev53242 - src/system/kernel - waddlesplash