Changeset 96e9434 in mainline for uspace/app/bdsh/exec.c


Ignore:
Timestamp:
2018-12-29T18:28:21Z (5 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
e70f1ae
Parents:
accdbd8
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

    raccdbd8 r96e9434  
    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 *);
     
    7673        size_t i;
    7774
    78         found = (char *)malloc(PATH_MAX);
    79 
    8075        /* The user has specified a full or relative path, just give it back. */
    8176        if (-1 != try_access(cmd)) {
    82                 return (char *) cmd;
     77                return str_dup(cmd);
    8378        }
    8479
     80        char *found = (char *)malloc(PATH_MAX);
    8581        /* We now have n places to look for the command */
    8682        for (i = 0; search_dir[i] != NULL; i++) {
     
    9187                }
    9288        }
     89        free(found);
    9390
    9491        /* We didn't find it, just give it back as-is. */
    95         return (char *) cmd;
     92        return str_dup(cmd);
    9693}
    9794
     
    107104        FILE *files[3];
    108105
    109         tmp = str_dup(find_command(cmd));
    110         free(found);
     106        tmp = find_command(cmd);
    111107
    112108        files[0] = io->stdin;
Note: See TracChangeset for help on using the changeset viewer.