Ticket #886: cage.2.patch

File cage.2.patch, 11.3 KB (added by jimmy, 12 years ago)
  • config/gen/platform/generic/exec.c

     
    5555    } 
    5656    else { 
    5757        /* child */ 
    58         char *cmd    = Parrot_str_to_cstring(interp, command); 
    59         int   status = execlp("sh", "sh", "-c", cmd, (void *)NULL); 
     58        char * const cmd    = Parrot_str_to_cstring(interp, command); 
     59        int          status = execlp("sh", "sh", "-c", cmd, (void *)NULL); 
    6060 
    6161        /* if we get here, something's horribly wrong, but free anyway... */ 
    62         mem_sys_free(cmd); 
     62        Parrot_str_free_cstring(cmd); 
    6363 
    6464        if (status) 
    6565            exit(status); 
     
    9797    if (child) { 
    9898        /* parent */ 
    9999        int status; 
    100         pid_t returnstat; 
    101         returnstat = waitpid(child, &status, 0); 
     100        pid_t returnstat = waitpid(child, &status, 0); 
    102101        UNUSED(returnstat); 
    103102        return status; 
    104103    } 
     
    106105        /* child. Be horribly profligate with memory, since we're 
    107106           about to be something else */ 
    108107        int status, i; 
    109         char **argv; 
    110108        STRING *s; 
    111         char *cmd; 
     109        char   *cmd; 
     110        char  **argv = (char **)mem_sys_allocate((len+1)*sizeof (char *)); 
    112111 
    113         argv = (char **)mem_sys_allocate((len+1)*sizeof (char *)); 
    114112        for (i = 0; i < len; ++i) { 
    115113            s = VTABLE_get_string_keyed_int(interp, cmdargs, i); 
    116114            argv[i] = Parrot_str_to_cstring(interp, s); 
    117115        } 
     116 
    118117        cmd = argv[0]; 
    119         argv[i] = NULL; 
    120118 
    121119        status = execvp(cmd, argv); 
    122120        /* if we get here, something's horribly wrong... */ 
     
    140138{ 
    141139    /* Be horribly profligate with memory, since we're 
    142140       about to be something else */ 
    143     char *cmd  = Parrot_str_to_cstring(interp, command); 
    144     int status = execlp("sh", "sh", "-c", cmd, (void *)NULL); 
     141    char * const cmd    = Parrot_str_to_cstring(interp, command); 
     142    int          status = execlp("sh", "sh", "-c", cmd, (void *)NULL); 
    145143 
    146144    /* if we get here, something's horribly wrong... */ 
    147145    if (status) 
  • config/gen/platform/win32/exec.c

     
    4141    DWORD status = 0; 
    4242    STARTUPINFO si; 
    4343    PROCESS_INFORMATION pi; 
    44     int free_it = 0; 
    45     char* cmd = (char *)mem_sys_allocate(command->strlen + 4); 
    46     char* shell = Parrot_getenv("ComSpec", &free_it); 
    47     char* cmdin = Parrot_str_to_cstring(interp, command); 
     44    int         free_it = 0; 
     45    char*       cmd      = (char *)mem_sys_allocate(command->strlen + 4); 
     46    char*       shell    = Parrot_getenv("ComSpec", &free_it); 
     47    char* const cmdin    = Parrot_str_to_cstring(interp, command); 
    4848 
    4949    strcpy(cmd, "/c "); 
    5050    strcat(cmd, cmdin); 
     
    9595    DWORD status = 0; 
    9696    STARTUPINFO si; 
    9797    PROCESS_INFORMATION pi; 
    98     int pmclen; 
     98    int pmclen, i; 
    9999    int cmdlinelen = 1000; 
    100100    int cmdlinepos = 0; 
    101     char *cmdline = (char *)mem_sys_allocate(cmdlinelen); 
    102     int i; 
     101    char *cmdline  = (char *)mem_sys_allocate(cmdlinelen); 
    103102 
    104103    /* Ensure there's something in the PMC array. */ 
    105104    pmclen = VTABLE_elements(interp, cmdargs); 
     
    109108 
    110109    /* Now build command line. */ 
    111110    for (i = 0; i < pmclen; i++) { 
    112         STRING *s = VTABLE_get_string_keyed_int(interp, cmdargs, i); 
    113         char *cs  = Parrot_str_to_cstring(interp, s); 
     111        STRING *     s  = VTABLE_get_string_keyed_int(interp, cmdargs, i); 
     112        char * const cs  = Parrot_str_to_cstring(interp, s); 
    114113        if (cmdlinepos + (int)s->strlen + 3 > cmdlinelen) { 
    115114            cmdlinelen += s->strlen + 4; 
    116115            cmdline = (char *)mem_sys_realloc(cmdline, cmdlinelen); 
     
    119118        strcpy(cmdline + cmdlinepos + 1, cs); 
    120119        strcpy(cmdline + cmdlinepos + 1 + s->strlen, "\" "); 
    121120        cmdlinepos += s->strlen + 3; 
     121                Parrot_str_free_cstring(cs); 
    122122    } 
    123123 
    124124    /* Start the child process. */ 
     
    162162Parrot_Exec_OS_Command(PARROT_INTERP, STRING *command) 
    163163{ 
    164164    int status; 
    165     char *in = Parrot_str_to_cstring(interp, command); 
    166     char *cmd = NULL; 
     165    char * const  in = Parrot_str_to_cstring(interp, command); 
     166    char *        cmd = NULL; 
    167167    const char **argv = (const char **)mem_sys_allocate_zeroed(2 * sizeof (int)); 
    168168 
    169169    /* Grab string, extract command and parameters. */ 
     
    223223        curPos ++; 
    224224    } 
    225225 
     226    Parrot_str_free_cstring(in); 
     227 
    226228    /* If we still have a seek char, then the input was improper. */ 
    227229    if (seekChar) 
    228230        Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_NOSPAWN, 
  • src/debug.c

     
    12561256            tmp_stdin, readline, 
    12571257            "S->S", prompt, & s); 
    12581258        { 
    1259         char * aux = Parrot_str_to_cstring(interpdeb, s); 
     1259        char * const aux = Parrot_str_to_cstring(interpdeb, s); 
    12601260        strcpy(c, aux); 
    12611261        Parrot_str_free_cstring(aux); 
    12621262        } 
  • src/dynext.c

     
    232232{ 
    233233    ASSERT_ARGS(dlopen_string) 
    234234 
    235     char *pathstr = Parrot_str_to_cstring(interp, path); 
    236     void *handle = Parrot_dlopen(pathstr); 
     235    char * const pathstr = Parrot_str_to_cstring(interp, path); 
     236    void *       handle = Parrot_dlopen(pathstr); 
    237237    Parrot_str_free_cstring(pathstr); 
    238238    return handle; 
    239239} 
  • src/interp/inter_misc.c

     
    346346 
    347347            else { 
    348348                /* Need to strip back to what follows the final / or \. */ 
    349                 STRING *fullname   = VTABLE_get_string(interp, exe_name); 
    350                 char   *fullname_c = Parrot_str_to_cstring(interp, fullname); 
    351                 int     pos        = strlen(fullname_c) - 1; 
     349                STRING *       fullname   = VTABLE_get_string(interp, exe_name); 
     350                char   * const fullname_c = Parrot_str_to_cstring(interp, fullname); 
     351                int            pos        = strlen(fullname_c) - 1; 
    352352 
    353353                while (pos              >  0 
    354354                &&     fullname_c[pos] != '/' 
     
    359359                    pos++; 
    360360 
    361361                basename = Parrot_str_new(interp, fullname_c + pos, 0); 
    362                 mem_sys_free(fullname_c); 
     362                Parrot_str_free_cstring(fullname_c); 
    363363 
    364364                return basename; 
    365365            } 
  • src/io/socket_unix.c

     
    105105    PMC  * const sockaddr = pmc_new(interp, enum_class_Sockaddr); 
    106106 
    107107    get_sockaddr_in(interp, sockaddr, s, port); 
    108     free(s); 
     108    Parrot_str_free_cstring(s); 
    109109    return sockaddr; 
    110110} 
    111111 
  • src/io/socket_win32.c

     
    444444{ 
    445445    ASSERT_ARGS(Parrot_io_sockaddr_in) 
    446446    PMC * sockaddr; 
    447     char * s; 
     447    char * const s = Parrot_str_to_cstring(interp, addr); 
    448448 
    449     s = Parrot_str_to_cstring(interp, addr); 
    450449    sockaddr = pmc_new(interp, enum_class_Sockaddr); 
    451450    get_sockaddr_in(interp, sockaddr, s, port); 
    452     free(s); 
     451    Parrot_str_free_cstring(s); 
    453452    return sockaddr; 
    454453} 
    455454 
  • src/io/unix.c

     
    756756    } 
    757757 
    758758#  else 
    759     UNUSED(l); 
     759    UNUSED(filehandle); 
    760760    UNUSED(command); 
    761761    UNUSED(flags); 
    762762    Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED, 
  • src/io/win32.c

     
    693693            NULL, NULL, TRUE, 0, 
    694694            NULL, NULL, &start, &procinfo) == 0) 
    695695        goto fail; 
    696     Parrot_str_free_cstring(cmd); 
    697     cmd = NULL; 
     696     
    698697    if (f_read) { 
    699698        Parrot_io_set_os_handle(interp, io, hread); 
    700699        CloseHandle(hwrite); 
     
    703702        Parrot_io_set_os_handle(interp, io, hwrite); 
    704703        CloseHandle(hread); 
    705704    } 
     705 
     706    Parrot_str_free_cstring(cmd); 
    706707    CloseHandle(procinfo.hThread); 
    707708    VTABLE_set_integer_keyed_int(interp, io, 0, (INTVAL)procinfo.hProcess); 
    708709    return io; 
  • src/pmc/codestring.pmc

     
    286286 
    287287  METHOD charname_to_ord(STRING *name) { 
    288288#if PARROT_HAS_ICU 
    289     UChar32    codepoint; 
    290     UErrorCode err       = U_ZERO_ERROR; 
    291     char       *cstr     = Parrot_str_to_cstring(INTERP, name); 
     289    UChar32      codepoint; 
     290    UErrorCode   err      = U_ZERO_ERROR; 
     291    char * const cstr     = Parrot_str_to_cstring(INTERP, name); 
    292292    codepoint = u_charFromName(U_EXTENDED_CHAR_NAME, cstr, &err); 
    293293    Parrot_str_free_cstring(cstr); 
    294294    if (U_SUCCESS(err)) { 
  • src/pmc/env.pmc

     
    340340=head1 SEE ALS0 
    341341 
    342342PDD - 
    343 L<http://www.parrotcode.org/docs/pdd/pdd17_pdd.html#Hash_types> 
     343L<http://docs.parrot.org/parrot/latest/html/docs/pdds/pdd17_pmc.pod.html#Hash_types> 
    344344 
    345345Environment in Perl 6 - L<http://dev.perl.org/perl6/rfc/318.html> 
    346346 
  • src/pmc/os.pmc

     
    476476*/ 
    477477    METHOD readdir(STRING *path) { 
    478478#ifndef _MSC_VER 
     479        char  * const cpath = Parrot_str_to_cstring(interp, path); 
     480        DIR           *dir  = opendir(cpath); 
    479481        struct dirent *dirent; 
    480482        PMC           *array; 
    481         char          *cpath = Parrot_str_to_cstring(interp, path); 
    482483        STRING        *retval; 
    483         DIR           *dir   = opendir(cpath); 
    484484 
    485485        Parrot_str_free_cstring(cpath); 
    486486 
  • src/pmc/string.pmc

     
    241241    VTABLE void set_string_native(STRING *value) { 
    242242        /* Only allow constant PMCs to embed constant strings */ 
    243243        if (PObj_constant_TEST(SELF) && !PObj_constant_TEST(value)) { 
    244             char *copy = Parrot_str_to_cstring(INTERP, value); 
    245             value      = Parrot_str_new_init(INTERP, copy, strlen(copy), 
     244            char * const copy = Parrot_str_to_cstring(INTERP, value); 
     245            value             = Parrot_str_new_init(INTERP, copy, strlen(copy), 
    246246                    PARROT_DEFAULT_ENCODING, PARROT_DEFAULT_CHARSET, PObj_constant_FLAG); 
    247247            Parrot_str_free_cstring(copy); 
    248248        }