Changeset f6d2c81 in mainline for uspace/libc/generic/thread.c


Ignore:
Timestamp:
2007-05-30T19:50:24Z (18 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c31e536
Parents:
51ec40f
Message:

Fix two memory leaks.

In kernel, kernel_uarg structure needs to be deallocated when a thread
with userspace context is destroyed.

In userspace, the return value of the SYS_THREAD_CREATE must be checked
for error conditions and in case of error, uarg and stack must be freed
up.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/libc/generic/thread.c

    r51ec40f rf6d2c81  
    7878         * Zero out the thread local uninitialized data.
    7979         */
    80         memset(data + (&_tbss_start - &_tdata_start), 0, &_tbss_end -
    81                 &_tbss_start);
     80        memset(data + (&_tbss_start - &_tdata_start), 0,
     81            &_tbss_end - &_tbss_start);
    8282
    8383        return tcb;
     
    129129 * @return Zero on success or a code from @ref errno.h on failure.
    130130 */
    131 int thread_create(void (* function)(void *), void *arg, char *name, thread_id_t *tid)
     131int thread_create(void (* function)(void *), void *arg, char *name,
     132    thread_id_t *tid)
    132133{
    133134        char *stack;
    134135        uspace_arg_t *uarg;
     136        int rc;
    135137
    136138        stack = (char *) malloc(getpagesize() * THREAD_INITIAL_STACK_PAGES_NO);
     
    150152        uarg->uspace_uarg = uarg;
    151153       
    152         return __SYSCALL3(SYS_THREAD_CREATE, (sysarg_t) uarg, (sysarg_t) name, (sysarg_t) tid);
     154        rc = __SYSCALL3(SYS_THREAD_CREATE, (sysarg_t) uarg, (sysarg_t) name,
     155            (sysarg_t) tid);
     156       
     157        if (!rc) {
     158                /*
     159                 * Failed to create a new thread.
     160                 * Free up the allocated structures.
     161                 */
     162                free(uarg);
     163                free(stack);
     164        }
     165
     166        return rc;
    153167}
    154168
Note: See TracChangeset for help on using the changeset viewer.