Changeset f6d2c81 in mainline


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.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/proc/task.c

    r51ec40f rf6d2c81  
    108108                t = NULL;
    109109                link_t *cur;
    110                 for (cur = tasks_btree.leaf_head.next; cur != &tasks_btree.leaf_head; cur = cur->next) {
    111                         btree_node_t *node = list_get_instance(cur, btree_node_t, leaf_link);
     110                for (cur = tasks_btree.leaf_head.next;
     111                    cur != &tasks_btree.leaf_head; cur = cur->next) {
     112                        btree_node_t *node;
     113                       
     114                        node = list_get_instance(cur, btree_node_t, leaf_link);
    112115                       
    113116                        unsigned int i;
     
    222225 * @return Task of the running program or NULL on error.
    223226 */
    224 task_t * task_run_program(void *program_addr, char *name)
     227task_t *task_run_program(void *program_addr, char *name)
    225228{
    226229        as_t *as;
  • kernel/generic/src/proc/thread.c

    r51ec40f rf6d2c81  
    300300                task_destroy(t->task);
    301301       
     302        /*
     303         * If the thread had a userspace context, free up its kernel_uarg
     304         * structure.
     305         */
     306        if (t->flags & THREAD_FLAG_USPACE) {
     307                ASSERT(t->thread_arg);
     308                free(t->thread_arg);
     309        }
     310
    302311        slab_free(thread_slab, t);
    303312}
     
    313322 * @param name      Symbolic name.
    314323 * @param uncounted Thread's accounting doesn't affect accumulated task
    315  *      accounting.
     324 *                  accounting.
    316325 *
    317326 * @return New thread's structure on success, NULL on failure.
     
    319328 */
    320329thread_t *thread_create(void (* func)(void *), void *arg, task_t *task,
    321         int flags, char *name, bool uncounted)
     330    int flags, char *name, bool uncounted)
    322331{
    323332        thread_t *t;
     
    638647 *
    639648 */
    640 unative_t sys_thread_create(uspace_arg_t *uspace_uarg, char *uspace_name, thread_id_t *uspace_thread_id)
     649unative_t sys_thread_create(uspace_arg_t *uspace_uarg, char *uspace_name,
     650    thread_id_t *uspace_thread_id)
    641651{
    642652        thread_t *t;
     
    661671                thread_ready(t);
    662672                if (uspace_thread_id != NULL)
    663                         return (unative_t) copy_to_uspace(uspace_thread_id, &t->tid,
    664                             sizeof(t->tid));
     673                        return (unative_t) copy_to_uspace(uspace_thread_id,
     674                            &t->tid, sizeof(t->tid));
    665675                else
    666676                        return 0;
  • 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.