rem: kfree(q); kfree(temp_name);
context: create_port(int32 queue_length, const char *name){	int 	i;	int 	state;	sem_id 	sem_r, sem_w;	port_id retval;	char 	*temp_name;	void 	*q;	team_id	owner;		if (ports_active == false)		return B_BAD_PORT_ID;	// check & dup name	if (name) {		int name_len = strlen(name);		temp_name = (char *)kmalloc(min(name_len + 1, SYS_MAX_OS_NAME_LEN));		if(temp_name == NULL)			return ENOMEM;		strncpy(temp_name, name, SYS_MAX_OS_NAME_LEN-1);		temp_name[SYS_MAX_OS_NAME_LEN-1] = 0;	} else {		temp_name = (char *)kmalloc(sizeof("default_port_name")+1);		if(temp_name == NULL)			return ENOMEM;		strcpy(temp_name, "default_port_name");	}		// check queue length & alloc	if (queue_length < 1)		return EINVAL;	if (queue_length > MAX_QUEUE_LENGTH)		return EINVAL;	q = (void *)kmalloc( queue_length * sizeof(struct port_msg) );	if (q == NULL) {		kfree(temp_name); // dealloc name, too		return ENOMEM;	}	// create sem_r with owner set to -1	sem_r = create_sem_etc(0, temp_name, -1);	if (sem_r < 0) {		// cleanup		kfree(temp_name);		kfree(q);		return sem_r;	}	// create sem_w	sem_w = create_sem_etc(queue_length, temp_name, -1);	if (sem_w < 0) {		// cleanup		delete_sem(sem_r);		kfree(temp_name);		kfree(q);		return sem_w;	}	owner = team_get_current_team_id();	state = disable_interrupts();	GRAB_PORT_LIST_LOCK();	// find the first empty spot	for(i=0; i<MAX_PORTS; i++) {		if(ports[i].id == -1) {			// make the port_id be a multiple of the slot it's in			if(i >= next_port % MAX_PORTS) {				next_port += i - next_port % MAX_PORTS;			} else {				next_port += MAX_PORTS - (next_port % MAX_PORTS - i);			}			ports[i].id		= next_port++;			ports[i].lock	= 0;			GRAB_PORT_LOCK(ports[i]);			RELEASE_PORT_LIST_LOCK();			ports[i].capacity	= queue_length;			ports[i].name 		= temp_name;			// assign sem			ports[i].read_sem	= sem_r;			ports[i].write_sem	= sem_w;			ports[i].msg_queue	= q;			ports[i].head 		= 0;			ports[i].tail 		= 0;			ports[i].total_count= 0;			ports[i].owner 		= owner;			retval = ports[i].id;			RELEASE_PORT_LOCK(ports[i]);			goto out;		}	}	// not enough ports...	RELEASE_PORT_LIST_LOCK();	kfree(q);	kfree(temp_name);	retval = B_NO_MORE_PORTS;	dprintf("create_port(): B_NO_MORE_PORTS\n");	// cleanup	delete_sem(sem_w);	delete_sem(sem_r);	kfree(temp_name);	kfree(q);out:	restore_interrupts(state);	return retval;}