Fossil SCM
memory allocated with mprintf should be freed with fossil_free(), not free() <p>use _wsystem() in stead of system() on Windows. <p>Use g.argv[0] in stead of fossil_nameofexec() when the full path is not necessary, e.g for "Usage" prints.
Commit
06ba3ace2440bf3b2b4f5aebdaea707189cc7a6e
Parent
2b56641fb941a72…
1 file changed
+21
-15
+21
-15
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -574,12 +574,13 @@ | ||
| 574 | 574 | if( g.cgiOutput && once ){ |
| 575 | 575 | once = 0; |
| 576 | 576 | cgi_printf("<p class=\"generalError\">%h</p>", z); |
| 577 | 577 | cgi_reply(); |
| 578 | 578 | }else if( !g.fQuiet ){ |
| 579 | - char *zOut = mprintf("%s: %s\n", fossil_nameofexe(), z); | |
| 579 | + char *zOut = mprintf("%s: %s\n", g.argv[0], z); | |
| 580 | 580 | fossil_puts(zOut, 1); |
| 581 | + fossil_free(zOut); | |
| 581 | 582 | } |
| 582 | 583 | } |
| 583 | 584 | free(z); |
| 584 | 585 | db_force_rollback(); |
| 585 | 586 | fossil_exit(rc); |
| @@ -606,12 +607,13 @@ | ||
| 606 | 607 | if( g.cgiOutput ){ |
| 607 | 608 | g.cgiOutput = 0; |
| 608 | 609 | cgi_printf("<p class=\"generalError\">%h</p>", z); |
| 609 | 610 | cgi_reply(); |
| 610 | 611 | }else if( !g.fQuiet ){ |
| 611 | - char *zOut = mprintf("\r%s: %s\n", fossil_nameofexe(), z); | |
| 612 | + char *zOut = mprintf("\r%s: %s\n", g.argv[0], z); | |
| 612 | 613 | fossil_puts(zOut, 1); |
| 614 | + fossil_free(zOut); | |
| 613 | 615 | } |
| 614 | 616 | } |
| 615 | 617 | free(z); |
| 616 | 618 | db_force_rollback(); |
| 617 | 619 | fossil_exit(rc); |
| @@ -647,13 +649,13 @@ | ||
| 647 | 649 | if( g.cgiOutput ){ |
| 648 | 650 | g.cgiOutput = 0; |
| 649 | 651 | cgi_printf("<p class=\"generalError\">%h</p>", z); |
| 650 | 652 | cgi_reply(); |
| 651 | 653 | }else{ |
| 652 | - char *zOut = mprintf("\r%s: %s\n", fossil_nameofexe(), z); | |
| 654 | + char *zOut = mprintf("\r%s: %s\n", g.argv[0], z); | |
| 653 | 655 | fossil_puts(zOut, 1); |
| 654 | - free(zOut); | |
| 656 | + fossil_free(zOut); | |
| 655 | 657 | } |
| 656 | 658 | } |
| 657 | 659 | db_force_rollback(); |
| 658 | 660 | fossil_exit(rc); |
| 659 | 661 | } |
| @@ -673,13 +675,13 @@ | ||
| 673 | 675 | #endif |
| 674 | 676 | { |
| 675 | 677 | if( g.cgiOutput ){ |
| 676 | 678 | cgi_printf("<p class=\"generalError\">%h</p>", z); |
| 677 | 679 | }else{ |
| 678 | - char *zOut = mprintf("\r%s: %s\n", fossil_nameofexe(), z); | |
| 680 | + char *zOut = mprintf("\r%s: %s\n", g.argv[0], z); | |
| 679 | 681 | fossil_puts(zOut, 1); |
| 680 | - free(zOut); | |
| 682 | + fossil_free(zOut); | |
| 681 | 683 | } |
| 682 | 684 | } |
| 683 | 685 | free(z); |
| 684 | 686 | } |
| 685 | 687 | |
| @@ -708,14 +710,18 @@ | ||
| 708 | 710 | #if defined(_WIN32) |
| 709 | 711 | /* On windows, we have to put double-quotes around the entire command. |
| 710 | 712 | ** Who knows why - this is just the way windows works. |
| 711 | 713 | */ |
| 712 | 714 | char *zNewCmd = mprintf("\"%s\"", zOrigCmd); |
| 713 | - char *zMbcs = fossil_utf8_to_mbcs(zNewCmd); | |
| 714 | - if( g.fSystemTrace ) fprintf(stderr, "SYSTEM: %s\n", zMbcs); | |
| 715 | - rc = system(zMbcs); | |
| 716 | - fossil_mbcs_free(zMbcs); | |
| 715 | + wchar_t *zUnicode = fossil_utf8_to_unicode(zNewCmd); | |
| 716 | + if( g.fSystemTrace ) { | |
| 717 | + char *zOut = mprintf("SYSTEM: %s\n", zNewCmd); | |
| 718 | + fossil_puts(zOut, 1); | |
| 719 | + fossil_free(zOut); | |
| 720 | + } | |
| 721 | + rc = _wsystem(zUnicode); | |
| 722 | + fossil_mbcs_free(zUnicode); | |
| 717 | 723 | free(zNewCmd); |
| 718 | 724 | #else |
| 719 | 725 | /* On unix, evaluate the command directly. |
| 720 | 726 | */ |
| 721 | 727 | if( g.fSystemTrace ) fprintf(stderr, "SYSTEM: %s\n", zOrigCmd); |
| @@ -781,11 +787,11 @@ | ||
| 781 | 787 | |
| 782 | 788 | /* |
| 783 | 789 | ** Print a usage comment and quit |
| 784 | 790 | */ |
| 785 | 791 | void usage(const char *zFormat){ |
| 786 | - fossil_fatal("Usage: %s %s %s\n", fossil_nameofexe(), g.argv[1], zFormat); | |
| 792 | + fossil_fatal("Usage: %s %s %s\n", g.argv[0], g.argv[1], zFormat); | |
| 787 | 793 | } |
| 788 | 794 | |
| 789 | 795 | /* |
| 790 | 796 | ** Remove n elements from g.argv beginning with the i-th element. |
| 791 | 797 | */ |
| @@ -942,11 +948,11 @@ | ||
| 942 | 948 | */ |
| 943 | 949 | void help_cmd(void){ |
| 944 | 950 | int rc, idx; |
| 945 | 951 | const char *z; |
| 946 | 952 | if( g.argc<3 ){ |
| 947 | - z = fossil_nameofexe(); | |
| 953 | + z = g.argv[0]; | |
| 948 | 954 | fossil_print( |
| 949 | 955 | "Usage: %s help COMMAND\n" |
| 950 | 956 | "Common COMMANDs: (use \"%s help --all\" for a complete list)\n", |
| 951 | 957 | z, z); |
| 952 | 958 | command_list(0, CMDFLAG_1ST_TIER); |
| @@ -981,11 +987,11 @@ | ||
| 981 | 987 | fossil_fatal("no help available for the %s command", |
| 982 | 988 | aCommand[idx].zName); |
| 983 | 989 | } |
| 984 | 990 | while( *z ){ |
| 985 | 991 | if( *z=='%' && strncmp(z, "%fossil", 7)==0 ){ |
| 986 | - fossil_print("%s", fossil_nameofexe()); | |
| 992 | + fossil_print("%s", g.argv[0]); | |
| 987 | 993 | z += 7; |
| 988 | 994 | }else{ |
| 989 | 995 | putchar(*z); |
| 990 | 996 | z++; |
| 991 | 997 | } |
| @@ -1028,11 +1034,11 @@ | ||
| 1028 | 1034 | } |
| 1029 | 1035 | *d = 0; |
| 1030 | 1036 | @ <blockquote><pre> |
| 1031 | 1037 | @ %h(z) |
| 1032 | 1038 | @ </pre></blockquote> |
| 1033 | - free(z); | |
| 1039 | + fossil_free(z); | |
| 1034 | 1040 | } |
| 1035 | 1041 | } |
| 1036 | 1042 | }else{ |
| 1037 | 1043 | int i, j, n; |
| 1038 | 1044 | |
| @@ -1687,11 +1693,11 @@ | ||
| 1687 | 1693 | while( zPath && zPath[0] ){ |
| 1688 | 1694 | while( zPath[0]==':' ) zPath++; |
| 1689 | 1695 | for(i=0; zPath[i] && zPath[i]!=':'; i++){} |
| 1690 | 1696 | zFull = mprintf("%.*s/%s", i, zPath, zBinary); |
| 1691 | 1697 | bExists = file_access(zFull, X_OK); |
| 1692 | - free(zFull); | |
| 1698 | + fossil_free(zFull); | |
| 1693 | 1699 | if( bExists==0 ) return 1; |
| 1694 | 1700 | zPath += i; |
| 1695 | 1701 | } |
| 1696 | 1702 | return 0; |
| 1697 | 1703 | } |
| 1698 | 1704 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -574,12 +574,13 @@ | |
| 574 | if( g.cgiOutput && once ){ |
| 575 | once = 0; |
| 576 | cgi_printf("<p class=\"generalError\">%h</p>", z); |
| 577 | cgi_reply(); |
| 578 | }else if( !g.fQuiet ){ |
| 579 | char *zOut = mprintf("%s: %s\n", fossil_nameofexe(), z); |
| 580 | fossil_puts(zOut, 1); |
| 581 | } |
| 582 | } |
| 583 | free(z); |
| 584 | db_force_rollback(); |
| 585 | fossil_exit(rc); |
| @@ -606,12 +607,13 @@ | |
| 606 | if( g.cgiOutput ){ |
| 607 | g.cgiOutput = 0; |
| 608 | cgi_printf("<p class=\"generalError\">%h</p>", z); |
| 609 | cgi_reply(); |
| 610 | }else if( !g.fQuiet ){ |
| 611 | char *zOut = mprintf("\r%s: %s\n", fossil_nameofexe(), z); |
| 612 | fossil_puts(zOut, 1); |
| 613 | } |
| 614 | } |
| 615 | free(z); |
| 616 | db_force_rollback(); |
| 617 | fossil_exit(rc); |
| @@ -647,13 +649,13 @@ | |
| 647 | if( g.cgiOutput ){ |
| 648 | g.cgiOutput = 0; |
| 649 | cgi_printf("<p class=\"generalError\">%h</p>", z); |
| 650 | cgi_reply(); |
| 651 | }else{ |
| 652 | char *zOut = mprintf("\r%s: %s\n", fossil_nameofexe(), z); |
| 653 | fossil_puts(zOut, 1); |
| 654 | free(zOut); |
| 655 | } |
| 656 | } |
| 657 | db_force_rollback(); |
| 658 | fossil_exit(rc); |
| 659 | } |
| @@ -673,13 +675,13 @@ | |
| 673 | #endif |
| 674 | { |
| 675 | if( g.cgiOutput ){ |
| 676 | cgi_printf("<p class=\"generalError\">%h</p>", z); |
| 677 | }else{ |
| 678 | char *zOut = mprintf("\r%s: %s\n", fossil_nameofexe(), z); |
| 679 | fossil_puts(zOut, 1); |
| 680 | free(zOut); |
| 681 | } |
| 682 | } |
| 683 | free(z); |
| 684 | } |
| 685 | |
| @@ -708,14 +710,18 @@ | |
| 708 | #if defined(_WIN32) |
| 709 | /* On windows, we have to put double-quotes around the entire command. |
| 710 | ** Who knows why - this is just the way windows works. |
| 711 | */ |
| 712 | char *zNewCmd = mprintf("\"%s\"", zOrigCmd); |
| 713 | char *zMbcs = fossil_utf8_to_mbcs(zNewCmd); |
| 714 | if( g.fSystemTrace ) fprintf(stderr, "SYSTEM: %s\n", zMbcs); |
| 715 | rc = system(zMbcs); |
| 716 | fossil_mbcs_free(zMbcs); |
| 717 | free(zNewCmd); |
| 718 | #else |
| 719 | /* On unix, evaluate the command directly. |
| 720 | */ |
| 721 | if( g.fSystemTrace ) fprintf(stderr, "SYSTEM: %s\n", zOrigCmd); |
| @@ -781,11 +787,11 @@ | |
| 781 | |
| 782 | /* |
| 783 | ** Print a usage comment and quit |
| 784 | */ |
| 785 | void usage(const char *zFormat){ |
| 786 | fossil_fatal("Usage: %s %s %s\n", fossil_nameofexe(), g.argv[1], zFormat); |
| 787 | } |
| 788 | |
| 789 | /* |
| 790 | ** Remove n elements from g.argv beginning with the i-th element. |
| 791 | */ |
| @@ -942,11 +948,11 @@ | |
| 942 | */ |
| 943 | void help_cmd(void){ |
| 944 | int rc, idx; |
| 945 | const char *z; |
| 946 | if( g.argc<3 ){ |
| 947 | z = fossil_nameofexe(); |
| 948 | fossil_print( |
| 949 | "Usage: %s help COMMAND\n" |
| 950 | "Common COMMANDs: (use \"%s help --all\" for a complete list)\n", |
| 951 | z, z); |
| 952 | command_list(0, CMDFLAG_1ST_TIER); |
| @@ -981,11 +987,11 @@ | |
| 981 | fossil_fatal("no help available for the %s command", |
| 982 | aCommand[idx].zName); |
| 983 | } |
| 984 | while( *z ){ |
| 985 | if( *z=='%' && strncmp(z, "%fossil", 7)==0 ){ |
| 986 | fossil_print("%s", fossil_nameofexe()); |
| 987 | z += 7; |
| 988 | }else{ |
| 989 | putchar(*z); |
| 990 | z++; |
| 991 | } |
| @@ -1028,11 +1034,11 @@ | |
| 1028 | } |
| 1029 | *d = 0; |
| 1030 | @ <blockquote><pre> |
| 1031 | @ %h(z) |
| 1032 | @ </pre></blockquote> |
| 1033 | free(z); |
| 1034 | } |
| 1035 | } |
| 1036 | }else{ |
| 1037 | int i, j, n; |
| 1038 | |
| @@ -1687,11 +1693,11 @@ | |
| 1687 | while( zPath && zPath[0] ){ |
| 1688 | while( zPath[0]==':' ) zPath++; |
| 1689 | for(i=0; zPath[i] && zPath[i]!=':'; i++){} |
| 1690 | zFull = mprintf("%.*s/%s", i, zPath, zBinary); |
| 1691 | bExists = file_access(zFull, X_OK); |
| 1692 | free(zFull); |
| 1693 | if( bExists==0 ) return 1; |
| 1694 | zPath += i; |
| 1695 | } |
| 1696 | return 0; |
| 1697 | } |
| 1698 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -574,12 +574,13 @@ | |
| 574 | if( g.cgiOutput && once ){ |
| 575 | once = 0; |
| 576 | cgi_printf("<p class=\"generalError\">%h</p>", z); |
| 577 | cgi_reply(); |
| 578 | }else if( !g.fQuiet ){ |
| 579 | char *zOut = mprintf("%s: %s\n", g.argv[0], z); |
| 580 | fossil_puts(zOut, 1); |
| 581 | fossil_free(zOut); |
| 582 | } |
| 583 | } |
| 584 | free(z); |
| 585 | db_force_rollback(); |
| 586 | fossil_exit(rc); |
| @@ -606,12 +607,13 @@ | |
| 607 | if( g.cgiOutput ){ |
| 608 | g.cgiOutput = 0; |
| 609 | cgi_printf("<p class=\"generalError\">%h</p>", z); |
| 610 | cgi_reply(); |
| 611 | }else if( !g.fQuiet ){ |
| 612 | char *zOut = mprintf("\r%s: %s\n", g.argv[0], z); |
| 613 | fossil_puts(zOut, 1); |
| 614 | fossil_free(zOut); |
| 615 | } |
| 616 | } |
| 617 | free(z); |
| 618 | db_force_rollback(); |
| 619 | fossil_exit(rc); |
| @@ -647,13 +649,13 @@ | |
| 649 | if( g.cgiOutput ){ |
| 650 | g.cgiOutput = 0; |
| 651 | cgi_printf("<p class=\"generalError\">%h</p>", z); |
| 652 | cgi_reply(); |
| 653 | }else{ |
| 654 | char *zOut = mprintf("\r%s: %s\n", g.argv[0], z); |
| 655 | fossil_puts(zOut, 1); |
| 656 | fossil_free(zOut); |
| 657 | } |
| 658 | } |
| 659 | db_force_rollback(); |
| 660 | fossil_exit(rc); |
| 661 | } |
| @@ -673,13 +675,13 @@ | |
| 675 | #endif |
| 676 | { |
| 677 | if( g.cgiOutput ){ |
| 678 | cgi_printf("<p class=\"generalError\">%h</p>", z); |
| 679 | }else{ |
| 680 | char *zOut = mprintf("\r%s: %s\n", g.argv[0], z); |
| 681 | fossil_puts(zOut, 1); |
| 682 | fossil_free(zOut); |
| 683 | } |
| 684 | } |
| 685 | free(z); |
| 686 | } |
| 687 | |
| @@ -708,14 +710,18 @@ | |
| 710 | #if defined(_WIN32) |
| 711 | /* On windows, we have to put double-quotes around the entire command. |
| 712 | ** Who knows why - this is just the way windows works. |
| 713 | */ |
| 714 | char *zNewCmd = mprintf("\"%s\"", zOrigCmd); |
| 715 | wchar_t *zUnicode = fossil_utf8_to_unicode(zNewCmd); |
| 716 | if( g.fSystemTrace ) { |
| 717 | char *zOut = mprintf("SYSTEM: %s\n", zNewCmd); |
| 718 | fossil_puts(zOut, 1); |
| 719 | fossil_free(zOut); |
| 720 | } |
| 721 | rc = _wsystem(zUnicode); |
| 722 | fossil_mbcs_free(zUnicode); |
| 723 | free(zNewCmd); |
| 724 | #else |
| 725 | /* On unix, evaluate the command directly. |
| 726 | */ |
| 727 | if( g.fSystemTrace ) fprintf(stderr, "SYSTEM: %s\n", zOrigCmd); |
| @@ -781,11 +787,11 @@ | |
| 787 | |
| 788 | /* |
| 789 | ** Print a usage comment and quit |
| 790 | */ |
| 791 | void usage(const char *zFormat){ |
| 792 | fossil_fatal("Usage: %s %s %s\n", g.argv[0], g.argv[1], zFormat); |
| 793 | } |
| 794 | |
| 795 | /* |
| 796 | ** Remove n elements from g.argv beginning with the i-th element. |
| 797 | */ |
| @@ -942,11 +948,11 @@ | |
| 948 | */ |
| 949 | void help_cmd(void){ |
| 950 | int rc, idx; |
| 951 | const char *z; |
| 952 | if( g.argc<3 ){ |
| 953 | z = g.argv[0]; |
| 954 | fossil_print( |
| 955 | "Usage: %s help COMMAND\n" |
| 956 | "Common COMMANDs: (use \"%s help --all\" for a complete list)\n", |
| 957 | z, z); |
| 958 | command_list(0, CMDFLAG_1ST_TIER); |
| @@ -981,11 +987,11 @@ | |
| 987 | fossil_fatal("no help available for the %s command", |
| 988 | aCommand[idx].zName); |
| 989 | } |
| 990 | while( *z ){ |
| 991 | if( *z=='%' && strncmp(z, "%fossil", 7)==0 ){ |
| 992 | fossil_print("%s", g.argv[0]); |
| 993 | z += 7; |
| 994 | }else{ |
| 995 | putchar(*z); |
| 996 | z++; |
| 997 | } |
| @@ -1028,11 +1034,11 @@ | |
| 1034 | } |
| 1035 | *d = 0; |
| 1036 | @ <blockquote><pre> |
| 1037 | @ %h(z) |
| 1038 | @ </pre></blockquote> |
| 1039 | fossil_free(z); |
| 1040 | } |
| 1041 | } |
| 1042 | }else{ |
| 1043 | int i, j, n; |
| 1044 | |
| @@ -1687,11 +1693,11 @@ | |
| 1693 | while( zPath && zPath[0] ){ |
| 1694 | while( zPath[0]==':' ) zPath++; |
| 1695 | for(i=0; zPath[i] && zPath[i]!=':'; i++){} |
| 1696 | zFull = mprintf("%.*s/%s", i, zPath, zBinary); |
| 1697 | bExists = file_access(zFull, X_OK); |
| 1698 | fossil_free(zFull); |
| 1699 | if( bExists==0 ) return 1; |
| 1700 | zPath += i; |
| 1701 | } |
| 1702 | return 0; |
| 1703 | } |
| 1704 |