| | @@ -344,34 +344,40 @@ |
| 344 | 344 | return buf; |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | /* |
| 348 | 348 | ** Adds v to the API-internal cleanup mechanism. key is ingored |
| 349 | | -** (legacy). If freeOnError is true then v is passed to |
| 350 | | -** cson_value_free() if the key cannot be inserted, otherweise |
| 351 | | -** ownership of v is not changed on error. Failure to insert an item |
| 352 | | -** may be caused by any of the following: |
| 349 | +** (legacy) but might be re-introduced and "should" be a unique |
| 350 | +** (app-wide) value. Failure to insert an item may be caused by any |
| 351 | +** of the following: |
| 353 | 352 | ** |
| 354 | 353 | ** - Allocation error. |
| 355 | 354 | ** - g.json.gc.a is NULL |
| 356 | 355 | ** - key is NULL or empty. |
| 357 | 356 | ** |
| 358 | 357 | ** Returns 0 on success. |
| 359 | 358 | ** |
| 360 | | -** On success, ownership of v is transfered to (or shared with) |
| 361 | | -** g.json.gc, and v will be valid until that object is cleaned up or |
| 362 | | -** some internal code incorrectly removes it from the gc (which we |
| 363 | | -** never do). |
| 359 | +** Ownership of v is transfered to (or shared with) g.json.gc, and v |
| 360 | +** will be valid until that object is cleaned up or some internal code |
| 361 | +** incorrectly removes it from the gc (which we never do). If this |
| 362 | +** function fails, it is fatal to the app (as it indicates an |
| 363 | +** allocation error (more likely than not) or a serious internal error |
| 364 | +** such as numeric overflow). |
| 364 | 365 | */ |
| 365 | | -int json_gc_add( char const * key, cson_value * v, char freeOnError ){ |
| 366 | +void json_gc_add( char const * key, cson_value * v ){ |
| 366 | 367 | int const rc = cson_array_append( g.json.gc.a, v ); |
| 367 | 368 | assert( NULL != g.json.gc.a ); |
| 368 | | - if( (0 != rc) && freeOnError ){ |
| 369 | + if( 0 != rc ){ |
| 369 | 370 | cson_value_free( v ); |
| 370 | 371 | } |
| 371 | 372 | assert( (0==rc) && "Adding item to GC failed." ); |
| 372 | | - return rc; |
| 373 | + if(0!=rc){ |
| 374 | + fprintf(stderr,"%s: FATAL: alloc error.\n", fossil_nameofexe()); |
| 375 | + fossil_exit(1)/*not fossil_panic() b/c it might land us somewhere |
| 376 | + where this function is called again. |
| 377 | + */; |
| 378 | + } |
| 373 | 379 | } |
| 374 | 380 | |
| 375 | 381 | |
| 376 | 382 | /* |
| 377 | 383 | ** Returns the value of json_rc_cstr(code) as a new JSON |
| | @@ -761,13 +767,12 @@ |
| 761 | 767 | */ |
| 762 | 768 | char const * zCookie = P(login_cookie_name()); |
| 763 | 769 | if( zCookie && *zCookie ){ |
| 764 | 770 | /* Transfer fossil's cookie to JSON for downstream convenience... */ |
| 765 | 771 | cson_value * v = cson_value_new_string(zCookie, strlen(zCookie)); |
| 766 | | - if(0 == json_gc_add( FossilJsonKeys.authToken, v, 1 )){ |
| 767 | | - g.json.authToken = v; |
| 768 | | - } |
| 772 | + json_gc_add( FossilJsonKeys.authToken, v ); |
| 773 | + g.json.authToken = v; |
| 769 | 774 | } |
| 770 | 775 | } |
| 771 | 776 | } |
| 772 | 777 | return g.json.authToken; |
| 773 | 778 | } |
| | @@ -822,11 +827,11 @@ |
| 822 | 827 | being of type string). |
| 823 | 828 | */ |
| 824 | 829 | v = cson_value_new_object(); |
| 825 | 830 | g.json.param.v = v; |
| 826 | 831 | g.json.param.o = cson_value_get_object(v); |
| 827 | | - json_gc_add("$PARAMS", v, 1); |
| 832 | + json_gc_add("$PARAMS", v); |
| 828 | 833 | } |
| 829 | 834 | |
| 830 | 835 | /* |
| 831 | 836 | ** Appends a warning object to the (pending) JSON response. |
| 832 | 837 | ** |
| | @@ -857,11 +862,11 @@ |
| 857 | 862 | && "Invalid warning code."); |
| 858 | 863 | if(!g.json.warnings.v){ |
| 859 | 864 | g.json.warnings.v = cson_value_new_array(); |
| 860 | 865 | assert((NULL != g.json.warnings.v) && "Alloc error."); |
| 861 | 866 | g.json.warnings.a = cson_value_get_array(g.json.warnings.v); |
| 862 | | - json_gc_add("$WARNINGS",g.json.warnings.v,0); |
| 867 | + json_gc_add("$WARNINGS",g.json.warnings.v); |
| 863 | 868 | } |
| 864 | 869 | obj = cson_new_object(); |
| 865 | 870 | cson_array_append(g.json.warnings.a, cson_object_value(obj)); |
| 866 | 871 | cson_object_set(obj,"code",cson_value_new_integer(code)); |
| 867 | 872 | if(fmt && *fmt){ |
| | @@ -1044,11 +1049,11 @@ |
| 1044 | 1049 | #endif |
| 1045 | 1050 | } |
| 1046 | 1051 | |
| 1047 | 1052 | g.json.cmd.v = cson_value_new_array(); |
| 1048 | 1053 | g.json.cmd.a = cson_value_get_array(g.json.cmd.v); |
| 1049 | | - json_gc_add( FossilJsonKeys.commandPath, g.json.cmd.v, 1 ); |
| 1054 | + json_gc_add( FossilJsonKeys.commandPath, g.json.cmd.v ); |
| 1050 | 1055 | /* |
| 1051 | 1056 | The following if/else block translates the PATH_INFO path (in |
| 1052 | 1057 | CLI/server modes) or g.argv (CLI mode) into an internal list so |
| 1053 | 1058 | that we can simplify command dispatching later on. |
| 1054 | 1059 | |
| 1055 | 1060 | |