Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset ba6232b in mainline


Ignore:
Timestamp:
2009-07-15T20:11:04Z (12 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master
Children:
aa7954f
Parents:
bf5443d
Message:

Fix a couple of memory leaks and an improper use of sizeof().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/util.c

    rbf5443d rba6232b  
    5454unsigned int cli_set_prompt(cliuser_t *usr)
    5555{
    56         usr->prompt = (char *) realloc(usr->prompt, PATH_MAX);
    57         if (NULL == usr->prompt) {
    58                 cli_error(CL_ENOMEM, "Can not allocate prompt");
    59                 cli_errno = CL_ENOMEM;
    60                 return 1;
    61         }
    62         memset(usr->prompt, 0, sizeof(usr->prompt));
    63 
    6456        usr->cwd = (char *) realloc(usr->cwd, PATH_MAX);
    6557        if (NULL == usr->cwd) {
     
    6860                return 1;
    6961        }
    70         memset(usr->cwd, 0, sizeof(usr->cwd));
    71 
    72         usr->cwd = getcwd(usr->cwd, PATH_MAX - 1);
    73 
    74         if (NULL == usr->cwd)
     62        if (!getcwd(usr->cwd, PATH_MAX))
    7563                snprintf(usr->cwd, PATH_MAX, "(unknown)");
    7664
     65        if (usr->prompt)
     66                free(usr->prompt);
    7767        asprintf(&usr->prompt, "%s # ", usr->cwd);
    7868
Note: See TracChangeset for help on using the changeset viewer.