44
55#include "foundation/compat_fs.h"
66#include "foundation/constants.h"
7+ #include "foundation/mem_core.h"
78#include "store/store.h"
89#include "yyjson/yyjson.h"
910
@@ -44,7 +45,7 @@ static char *adr_string_arg(const char *args, const char *key) {
4445 yyjson_val * root = doc ? yyjson_doc_get_root (doc ) : NULL ;
4546 yyjson_val * value = yyjson_is_obj (root ) ? yyjson_obj_get (root , key ) : NULL ;
4647 const char * text = yyjson_is_str (value ) ? yyjson_get_str (value ) : NULL ;
47- char * copy = text ? adr_strdup ( text ) : NULL ;
48+ char * copy = text ? cbm_mem_strdup ( CBM_MEM_CLASS_OPERATION_ARG , text ) : NULL ;
4849 if (doc )
4950 yyjson_doc_free (doc );
5051 return copy ;
@@ -394,28 +395,28 @@ cbm_operation_result_t cbm_adr_operation_execute(const char *args_json,
394395 char * mode = adr_string_arg (args , "mode" );
395396 char * content = adr_string_arg (args , "content" );
396397 if (!mode )
397- mode = adr_strdup ( "outline" );
398+ mode = cbm_mem_strdup ( CBM_MEM_CLASS_OPERATION_ARG , "outline" );
398399
399400 bool valid_mode = mode && (strcmp (mode , "outline" ) == 0 || strcmp (mode , "get" ) == 0 ||
400401 strcmp (mode , "sections" ) == 0 || strcmp (mode , "update" ) == 0 ||
401402 strcmp (mode , "set_sections" ) == 0 || strcmp (mode , "store" ) == 0 );
402403 if (!valid_mode ) {
403- free ( project );
404- free (mode );
405- free (content );
404+ cbm_free ( CBM_MEM_CLASS_OPERATION_ARG , project );
405+ cbm_operation_arg_free (mode );
406+ cbm_operation_arg_free (content );
406407 return adr_error ("invalid_arguments" ,
407408 "invalid mode: use outline, get, sections, set_sections, or update" );
408409 }
409410 if ((strcmp (mode , "update" ) == 0 || strcmp (mode , "store" ) == 0 ) && !content ) {
410- free ( project );
411- free (mode );
411+ cbm_free ( CBM_MEM_CLASS_OPERATION_ARG , project );
412+ cbm_operation_arg_free (mode );
412413 return adr_error ("invalid_arguments" , "content is required for update" );
413414 }
414415
415416 if (adr_has_removed_sections_arg (args )) {
416- free ( project );
417- free (mode );
418- free (content );
417+ cbm_free ( CBM_MEM_CLASS_OPERATION_ARG , project );
418+ cbm_operation_arg_free (mode );
419+ cbm_operation_arg_free (content );
419420 return adr_error ("invalid_arguments" , "The sections argument is not an update primitive "
420421 "and has been removed. No ADR write was performed." );
421422 }
@@ -435,9 +436,9 @@ cbm_operation_result_t cbm_adr_operation_execute(const char *args_json,
435436 if (updates .status ) {
436437 cbm_operation_result_t result = adr_error (updates .status , updates .error );
437438 adr_updates_free (& updates );
438- free ( project );
439- free (mode );
440- free (content );
439+ cbm_free ( CBM_MEM_CLASS_OPERATION_ARG , project );
440+ cbm_operation_arg_free (mode );
441+ cbm_operation_arg_free (content );
441442 return result ;
442443 }
443444 }
@@ -447,9 +448,9 @@ cbm_operation_result_t cbm_adr_operation_execute(const char *args_json,
447448 set_sections ;
448449 if (!runtime || !runtime -> store_resolve ) {
449450 adr_updates_free (& updates );
450- free ( project );
451- free (mode );
452- free (content );
451+ cbm_free ( CBM_MEM_CLASS_OPERATION_ARG , project );
452+ cbm_operation_arg_free (mode );
453+ cbm_operation_arg_free (content );
453454 return adr_error ("store_unavailable" ,
454455 "project store resolution is unavailable for this execution path" );
455456 }
@@ -459,18 +460,18 @@ cbm_operation_result_t cbm_adr_operation_execute(const char *args_json,
459460 if (!runtime -> mutation_begin || !runtime -> mutation_end ||
460461 !runtime -> mutation_begin (runtime -> mutation_context , project )) {
461462 adr_updates_free (& updates );
462- free ( project );
463- free (mode );
464- free (content );
463+ cbm_free ( CBM_MEM_CLASS_OPERATION_ARG , project );
464+ cbm_operation_arg_free (mode );
465+ cbm_operation_arg_free (content );
465466 return adr_error ("busy" , "project operation cancelled or blocked by an active index" );
466467 }
467468 mutation_held = true;
468469 if (runtime -> cancelled && runtime -> cancelled (runtime -> cancelled_context )) {
469470 runtime -> mutation_end (runtime -> mutation_context , project );
470471 adr_updates_free (& updates );
471- free ( project );
472- free (mode );
473- free (content );
472+ cbm_free ( CBM_MEM_CLASS_OPERATION_ARG , project );
473+ cbm_operation_arg_free (mode );
474+ cbm_operation_arg_free (content );
474475 return adr_error ("cancelled" , "project operation cancelled for this request" );
475476 }
476477 }
@@ -497,9 +498,9 @@ cbm_operation_result_t cbm_adr_operation_execute(const char *args_json,
497498 if (mutation_held )
498499 runtime -> mutation_end (runtime -> mutation_context , project );
499500 adr_updates_free (& updates );
500- free ( project );
501- free (mode );
502- free (content );
501+ cbm_free ( CBM_MEM_CLASS_OPERATION_ARG , project );
502+ cbm_operation_arg_free (mode );
503+ cbm_operation_arg_free (content );
503504 return result ;
504505 }
505506
@@ -511,9 +512,9 @@ cbm_operation_result_t cbm_adr_operation_execute(const char *args_json,
511512 if (mutation_held )
512513 runtime -> mutation_end (runtime -> mutation_context , project );
513514 adr_updates_free (& updates );
514- free ( project );
515- free (mode );
516- free (content );
515+ cbm_free ( CBM_MEM_CLASS_OPERATION_ARG , project );
516+ cbm_operation_arg_free (mode );
517+ cbm_operation_arg_free (content );
517518 return adr_error ("open_failed" , "failed to open writable ADR store" );
518519 }
519520 }
@@ -571,9 +572,9 @@ cbm_operation_result_t cbm_adr_operation_execute(const char *args_json,
571572 adr_updates_free (& updates );
572573 free (legacy_seed );
573574 free (legacy );
574- free ( project );
575- free (mode );
576- free (content );
575+ cbm_free ( CBM_MEM_CLASS_OPERATION_ARG , project );
576+ cbm_operation_arg_free (mode );
577+ cbm_operation_arg_free (content );
577578 return cbm_operation_result_copy ("{\"error\":\"result allocation failed\"}" , true);
578579 }
579580 yyjson_mut_doc_set_root (doc , root );
@@ -656,8 +657,8 @@ cbm_operation_result_t cbm_adr_operation_execute(const char *args_json,
656657 adr_updates_free (& updates );
657658 free (legacy_seed );
658659 free (legacy );
659- free ( project );
660- free (mode );
661- free (content );
660+ cbm_free ( CBM_MEM_CLASS_OPERATION_ARG , project );
661+ cbm_operation_arg_free (mode );
662+ cbm_operation_arg_free (content );
662663 return result ;
663664}
0 commit comments