kernel/port: Let the mutex take care of cloning the name.

This way, we can just call mutex_destroy to take care of
freeing it. No functional change intended.
This commit is contained in:
Augustin Cavalier
2019-11-23 14:05:17 -05:00
parent 0bf9e7cb16
commit 3c47c28a67
+5 -13
View File
@@ -132,7 +132,7 @@ struct Port : public KernelReferenceable {
select_info* select_infos; select_info* select_infos;
MessageList messages; MessageList messages;
Port(team_id owner, int32 queueLength, char* name) Port(team_id owner, int32 queueLength, const char* name)
: :
owner(owner), owner(owner),
name_hash(0), name_hash(0),
@@ -145,7 +145,7 @@ struct Port : public KernelReferenceable {
{ {
// id is initialized when the caller adds the port to the hash table // id is initialized when the caller adds the port to the hash table
mutex_init(&lock, name); mutex_init_etc(&lock, name, MUTEX_FLAG_CLONE_NAME);
read_condition.Init(this, "port read"); read_condition.Init(this, "port read");
write_condition.Init(this, "port write"); write_condition.Init(this, "port write");
} }
@@ -155,8 +155,7 @@ struct Port : public KernelReferenceable {
while (port_message* message = messages.RemoveHead()) while (port_message* message = messages.RemoveHead())
put_port_message(message); put_port_message(message);
free((char*)lock.name); mutex_destroy(&lock);
lock.name = NULL;
} }
}; };
@@ -988,18 +987,11 @@ create_port(int32 queueLength, const char* name)
if (team == NULL) if (team == NULL)
return B_BAD_TEAM_ID; return B_BAD_TEAM_ID;
// check & dup name
char* nameBuffer = strdup(name != NULL ? name : "unnamed port");
if (nameBuffer == NULL)
return B_NO_MEMORY;
// create a port // create a port
Port* port = new(std::nothrow) Port(team_get_current_team_id(), queueLength, Port* port = new(std::nothrow) Port(team_get_current_team_id(), queueLength,
nameBuffer); name != NULL ? name : "unnamed port");
if (port == NULL) { if (port == NULL)
free(nameBuffer);
return B_NO_MEMORY; return B_NO_MEMORY;
}
// check the ports limit // check the ports limit
const int32 previouslyUsed = atomic_add(&sUsedPorts, 1); const int32 previouslyUsed = atomic_add(&sUsedPorts, 1);