Ticket #147: escaping-patch-rev4.patch

File escaping-patch-rev4.patch, 5.3 KB (added by slavazanko, 15 years ago)

fix some memory leaks. WARNING: patch don't allyped to '147_escaping' branch

  • src/command.c

    diff --git a/src/command.c b/src/command.c
    index b204b8d..ba0a5b3 100644
    a b examine_cd (char *path) 
    6464    const char *t; 
    6565 
    6666    /* Tilde expansion */ 
     67    p = path; 
     68    path = unescape_string(path); 
     69    g_free(p); 
    6770    path_tilde = tilde_expand (path); 
    6871 
    6972    /* Leave space for further expansion */ 
  • src/complete.c

    diff --git a/src/complete.c b/src/complete.c
    index 1742b85..3ac0c21 100644
    a b  
    4040#include "wtools.h" 
    4141#include "complete.h" 
    4242#include "main.h" 
     43#include "util.h" 
    4344#include "key.h"                /* XCTRL and ALT macros */ 
    4445 
    4546typedef char *CompletionFunction (char *, int); 
    query_callback (Dlg_head *h, dlg_msg_t msg, int parm) 
    911912static int 
    912913complete_engine (WInput *in, int what_to_do) 
    913914{ 
     915    char *complete = NULL; 
    914916    if (in->completions && in->point != end) 
    915917        free_completions (in); 
    916918    if (!in->completions){ 
    complete_engine (WInput *in, int what_to_do) 
    924926    } 
    925927    if (in->completions){ 
    926928        if (what_to_do & DO_INSERTION || ((what_to_do & DO_QUERY) && !in->completions[1])) { 
    927             if (insert_text (in, in->completions [0], strlen (in->completions [0]))){ 
     929            complete = escape_string(in->completions [0]); 
     930            if (insert_text (in, complete, strlen (complete))){ 
    928931                if (in->completions [1]) 
    929932                    beep (); 
    930933                else 
    931934                    free_completions (in); 
    932935            } else 
    933936                beep (); 
     937            g_free(complete); 
    934938        } 
    935939        if ((what_to_do & DO_QUERY) && in->completions && in->completions [1]) { 
    936940            int maxlen = 0, i, count = 0; 
    complete_engine (WInput *in, int what_to_do) 
    940944            Dlg_head *query_dlg; 
    941945            WListbox *query_list; 
    942946             
    943             for (p=in->completions + 1; *p; count++, p++) 
     947            for (p=in->completions + 1; *p; count++, p++) { 
     948/*          *p = escape_string(*p); */ 
    944949                if ((i = strlen (*p)) > maxlen) 
    945950                    maxlen = i; 
     951                        } 
    946952            start_x = in->widget.x; 
    947953            start_y = in->widget.y; 
    948954            if (start_y - 2 >= count) { 
  • src/file.c

    diff --git a/src/file.c b/src/file.c
    index a19633a..27ff6c2 100644
    a b  
    6363#include "widget.h" 
    6464#include "wtools.h" 
    6565#include "background.h"         /* we_are_background */ 
     66#include "util.h" 
    6667 
    6768/* Needed for current_panel, other_panel and WTree */ 
    6869#include "dir.h" 
    copy_file_file (FileOpContext *ctx, const char *src_path, const char *dst_path, 
    791792            } 
    792793        } 
    793794 
    794         if (!appending) { 
     795        if (!appending && ctx->preserve) { 
    795796            while (mc_chmod (dst_path, (src_mode & ctx->umask_kill))) { 
    796797                temp_status = file_error ( 
    797798                        _(" Cannot chmod target file \"%s\" \n %s "), dst_path); 
    panel_operate (void *source_panel, FileOperation operation, 
    18701871                char *temp2 = concat_dir_and_file (dest, temp); 
    18711872                g_free (dest); 
    18721873                dest = temp2; 
    1873                 temp = NULL; 
    1874  
     1874                temp = NULL; /* where g_free(temp) ?*/ 
     1875 
     1876                temp2 = source_with_path; 
     1877                source_with_path = unescape_string(source_with_path); 
     1878                g_free(temp2); 
     1879                temp2 = dest; 
     1880                dest = unescape_string(dest); 
     1881                g_free(temp2); 
    18751882                switch (operation) { 
    18761883                case OP_COPY: 
    18771884                    /* 
    panel_operate (void *source_panel, FileOperation operation, 
    19621969                    value = transform_error; 
    19631970                else { 
    19641971                    char *temp2 = concat_dir_and_file (dest, temp); 
     1972                    char *temp3; 
     1973 
     1974                        temp3 = source_with_path; 
     1975                        source_with_path = unescape_string(source_with_path); 
     1976                        g_free(temp3); 
     1977                        temp3 = temp2; 
     1978                        temp2 = unescape_string(temp2); 
     1979                        g_free(temp3); 
    19651980 
    19661981                    switch (operation) { 
    19671982                    case OP_COPY: 
  • src/util.c

    diff --git a/src/util.c b/src/util.c
    index da6d1b2..b076168 100644
    a b Q_ (const char *s) 
    15251525    return (sep != NULL) ? sep + 1 : result; 
    15261526} 
    15271527 
     1528/* Unescape paths or other strings for e.g the internal cd  */ 
     1529char * 
     1530unescape_string(const char *in) { 
     1531    GString *str; 
     1532    const char * src; 
     1533    char *result; 
     1534 
     1535    str = g_string_new(""); 
     1536 
     1537    for (src = in; *src != '\0'; src++) { 
     1538        if (src[0] == '\\' && strchr(" !#$%&'()*;<>?[]`{|}~", src[1])) { 
     1539            g_string_append_c(str, src[1]); 
     1540            src++; 
     1541        } else { 
     1542            g_string_append_c(str, src[0]); 
     1543        } 
     1544    } 
     1545 
     1546    result = str->str; 
     1547    g_string_free(str, FALSE); 
     1548    return result; 
     1549} 
     1550/* To be compatible with the general posix command lines we have to escape * 
     1551 * strings for the command line                                                                                    */ 
     1552char * 
     1553escape_string ( const char * in ) { 
     1554        GString *str; 
     1555        const char * src; 
     1556        char *result; 
     1557 
     1558        str = g_string_new(""); 
     1559 
     1560        for (src = in;src[0] != '\0';src++) { 
     1561                if ( (src[-1] != '\\') && strchr(" !#$%&'()*;<>?[]`{|}~",src[0])) { 
     1562                        g_string_append_c(str,'\\'); 
     1563                        g_string_append_c(str,src[0]); 
     1564                } else { 
     1565                        g_string_append_c(str,src[0]); 
     1566                } 
     1567        } 
     1568 
     1569        result = str->str; 
     1570        g_string_free(str, FALSE); 
     1571        return result; 
     1572} 
  • src/util.h

    diff --git a/src/util.h b/src/util.h
    index 4e9a113..9c69e99 100644
    a b extern char *str_unconst (const char *); 
    1414extern const char *cstrcasestr (const char *haystack, const char *needle); 
    1515extern const char *cstrstr (const char *haystack, const char *needle); 
    1616 
     17char *unescape_string ( const char * in ); 
     18char *escape_string ( const char * in ); 
    1719void str_replace(char *s, char from, char to); 
    1820int  is_printable (int c); 
    1921void msglen (const char *text, /*@out@*/ int *lines, /*@out@*/ int *columns);