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.

jan.nijtmans 2012-09-04 08:14 trunk
Commit 06ba3ace2440bf3b2b4f5aebdaea707189cc7a6e
1 file changed +21 -15
+21 -15
--- src/main.c
+++ src/main.c
@@ -574,12 +574,13 @@
574574
if( g.cgiOutput && once ){
575575
once = 0;
576576
cgi_printf("<p class=\"generalError\">%h</p>", z);
577577
cgi_reply();
578578
}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);
580580
fossil_puts(zOut, 1);
581
+ fossil_free(zOut);
581582
}
582583
}
583584
free(z);
584585
db_force_rollback();
585586
fossil_exit(rc);
@@ -606,12 +607,13 @@
606607
if( g.cgiOutput ){
607608
g.cgiOutput = 0;
608609
cgi_printf("<p class=\"generalError\">%h</p>", z);
609610
cgi_reply();
610611
}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);
612613
fossil_puts(zOut, 1);
614
+ fossil_free(zOut);
613615
}
614616
}
615617
free(z);
616618
db_force_rollback();
617619
fossil_exit(rc);
@@ -647,13 +649,13 @@
647649
if( g.cgiOutput ){
648650
g.cgiOutput = 0;
649651
cgi_printf("<p class=\"generalError\">%h</p>", z);
650652
cgi_reply();
651653
}else{
652
- char *zOut = mprintf("\r%s: %s\n", fossil_nameofexe(), z);
654
+ char *zOut = mprintf("\r%s: %s\n", g.argv[0], z);
653655
fossil_puts(zOut, 1);
654
- free(zOut);
656
+ fossil_free(zOut);
655657
}
656658
}
657659
db_force_rollback();
658660
fossil_exit(rc);
659661
}
@@ -673,13 +675,13 @@
673675
#endif
674676
{
675677
if( g.cgiOutput ){
676678
cgi_printf("<p class=\"generalError\">%h</p>", z);
677679
}else{
678
- char *zOut = mprintf("\r%s: %s\n", fossil_nameofexe(), z);
680
+ char *zOut = mprintf("\r%s: %s\n", g.argv[0], z);
679681
fossil_puts(zOut, 1);
680
- free(zOut);
682
+ fossil_free(zOut);
681683
}
682684
}
683685
free(z);
684686
}
685687
@@ -708,14 +710,18 @@
708710
#if defined(_WIN32)
709711
/* On windows, we have to put double-quotes around the entire command.
710712
** Who knows why - this is just the way windows works.
711713
*/
712714
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);
717723
free(zNewCmd);
718724
#else
719725
/* On unix, evaluate the command directly.
720726
*/
721727
if( g.fSystemTrace ) fprintf(stderr, "SYSTEM: %s\n", zOrigCmd);
@@ -781,11 +787,11 @@
781787
782788
/*
783789
** Print a usage comment and quit
784790
*/
785791
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);
787793
}
788794
789795
/*
790796
** Remove n elements from g.argv beginning with the i-th element.
791797
*/
@@ -942,11 +948,11 @@
942948
*/
943949
void help_cmd(void){
944950
int rc, idx;
945951
const char *z;
946952
if( g.argc<3 ){
947
- z = fossil_nameofexe();
953
+ z = g.argv[0];
948954
fossil_print(
949955
"Usage: %s help COMMAND\n"
950956
"Common COMMANDs: (use \"%s help --all\" for a complete list)\n",
951957
z, z);
952958
command_list(0, CMDFLAG_1ST_TIER);
@@ -981,11 +987,11 @@
981987
fossil_fatal("no help available for the %s command",
982988
aCommand[idx].zName);
983989
}
984990
while( *z ){
985991
if( *z=='%' && strncmp(z, "%fossil", 7)==0 ){
986
- fossil_print("%s", fossil_nameofexe());
992
+ fossil_print("%s", g.argv[0]);
987993
z += 7;
988994
}else{
989995
putchar(*z);
990996
z++;
991997
}
@@ -1028,11 +1034,11 @@
10281034
}
10291035
*d = 0;
10301036
@ <blockquote><pre>
10311037
@ %h(z)
10321038
@ </pre></blockquote>
1033
- free(z);
1039
+ fossil_free(z);
10341040
}
10351041
}
10361042
}else{
10371043
int i, j, n;
10381044
@@ -1687,11 +1693,11 @@
16871693
while( zPath && zPath[0] ){
16881694
while( zPath[0]==':' ) zPath++;
16891695
for(i=0; zPath[i] && zPath[i]!=':'; i++){}
16901696
zFull = mprintf("%.*s/%s", i, zPath, zBinary);
16911697
bExists = file_access(zFull, X_OK);
1692
- free(zFull);
1698
+ fossil_free(zFull);
16931699
if( bExists==0 ) return 1;
16941700
zPath += i;
16951701
}
16961702
return 0;
16971703
}
16981704
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button