Changeset c56a3eb in mainline


Ignore:
Timestamp:
2019-03-02T15:22:12Z (5 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1c481ee
Parents:
951e451
git-author:
Matthieu Riolo <matthieu.riolo@…> (2018-12-29 18:28:21)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2019-03-02 15:22:12)
Message:

correcting find_command() which returns allocated strings

The old version of find_command() relied on a global variable called
'found'. This variable had to be released after every call on
find_command(). The old version did this immediatly after the call.

The code directly implied that this has to be changed with the following
comment:
'FIXME: Just have find_command() return an allocated string'

This commit removes the global variable, changes the implementation
of find_command() to return an allocated string and adds/removes
certain str_dup() calls to match the new implementation

File:
1 edited

Legend:

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

    r951e451 rc56a3eb  
    4747#include "errors.h"
    4848
    49 /* FIXME: Just have find_command() return an allocated string */
    50 static char *found;
    51 
    5249static char *find_command(char *);
    5350static int try_access(const char *);
     
    7471static char *find_command(char *cmd)
    7572{
    76         size_t i;
    77 
    78         found = (char *)malloc(PATH_MAX);
    79 
    8073        /* The user has specified a full or relative path, just give it back. */
    8174        if (-1 != try_access(cmd)) {
    82                 return (char *) cmd;
     75                return str_dup(cmd);
    8376        }
    8477
     78        char *found = (char *)malloc(PATH_MAX);
    8579        /* We now have n places to look for the command */
     80        size_t i;
    8681        for (i = 0; search_dir[i] != NULL; i++) {
    8782                memset(found, 0, PATH_MAX);
     
    9186                }
    9287        }
     88        free(found);
    9389
    9490        /* We didn't find it, just give it back as-is. */
    95         return (char *) cmd;
     91        return str_dup(cmd);
    9692}
    9793
     
    107103        FILE *files[3];
    108104
    109         tmp = str_dup(find_command(cmd));
    110         free(found);
     105        tmp = find_command(cmd);
    111106
    112107        files[0] = io->stdin;
Note: See TracChangeset for help on using the changeset viewer.