@@ -31,7 +31,16 @@ namespace Sass {
31
31
extern " C" {
32
32
using namespace Sass ;
33
33
34
- static void copy_options (struct Sass_Options * to, struct Sass_Options * from) { *to = *from; }
34
+ static void sass_clear_options (struct Sass_Options * options);
35
+ static void sass_reset_options (struct Sass_Options * options);
36
+ static void copy_options (struct Sass_Options * to, struct Sass_Options * from) {
37
+ // free assigned memory
38
+ sass_clear_options (to);
39
+ // move memory
40
+ *to = *from;
41
+ // Reset pointers on source
42
+ sass_reset_options (from);
43
+ }
35
44
36
45
#define IMPLEMENT_SASS_OPTION_ACCESSOR (type, option ) \
37
46
type ADDCALL sass_option_get_##option (struct Sass_Options * options) { return options->option ; } \
@@ -475,6 +484,24 @@ extern "C" {
475
484
return 0 ;
476
485
}
477
486
487
+ // helper function, not exported, only accessible locally
488
+ static void sass_reset_options (struct Sass_Options * options)
489
+ {
490
+ // free pointer before
491
+ // or copy/move them
492
+ options->input_path = 0 ;
493
+ options->output_path = 0 ;
494
+ options->plugin_path = 0 ;
495
+ options->include_path = 0 ;
496
+ options->source_map_file = 0 ;
497
+ options->source_map_root = 0 ;
498
+ options->c_functions = 0 ;
499
+ options->c_importers = 0 ;
500
+ options->c_headers = 0 ;
501
+ options->plugin_paths = 0 ;
502
+ options->include_paths = 0 ;
503
+ }
504
+
478
505
// helper function, not exported, only accessible locally
479
506
static void sass_clear_options (struct Sass_Options * options)
480
507
{
@@ -527,12 +554,25 @@ extern "C" {
527
554
cur = next;
528
555
}
529
556
}
557
+ // Free options strings
558
+ free (options->input_path );
559
+ free (options->output_path );
560
+ free (options->plugin_path );
561
+ free (options->include_path );
562
+ free (options->source_map_file );
563
+ free (options->source_map_root );
530
564
// Free custom functions
531
565
free (options->c_functions );
532
566
// Free custom importers
533
567
free (options->c_importers );
534
568
free (options->c_headers );
535
569
// Reset our pointers
570
+ options->input_path = 0 ;
571
+ options->output_path = 0 ;
572
+ options->plugin_path = 0 ;
573
+ options->include_path = 0 ;
574
+ options->source_map_file = 0 ;
575
+ options->source_map_root = 0 ;
536
576
options->c_functions = 0 ;
537
577
options->c_importers = 0 ;
538
578
options->c_headers = 0 ;
@@ -552,12 +592,6 @@ extern "C" {
552
592
if (ctx->error_text ) free (ctx->error_text );
553
593
if (ctx->error_json ) free (ctx->error_json );
554
594
if (ctx->error_file ) free (ctx->error_file );
555
- if (ctx->input_path ) free (ctx->input_path );
556
- if (ctx->output_path ) free (ctx->output_path );
557
- if (ctx->plugin_path ) free (ctx->plugin_path );
558
- if (ctx->include_path ) free (ctx->include_path );
559
- if (ctx->source_map_file ) free (ctx->source_map_file );
560
- if (ctx->source_map_root ) free (ctx->source_map_root );
561
595
free_string_array (ctx->included_files );
562
596
// play safe and reset properties
563
597
ctx->output_string = 0 ;
@@ -566,11 +600,6 @@ extern "C" {
566
600
ctx->error_text = 0 ;
567
601
ctx->error_json = 0 ;
568
602
ctx->error_file = 0 ;
569
- ctx->input_path = 0 ;
570
- ctx->output_path = 0 ;
571
- ctx->include_path = 0 ;
572
- ctx->source_map_file = 0 ;
573
- ctx->source_map_root = 0 ;
574
603
ctx->included_files = 0 ;
575
604
// now clear the options
576
605
sass_clear_options (ctx);
@@ -587,6 +616,11 @@ extern "C" {
587
616
free (compiler);
588
617
}
589
618
619
+ void ADDCALL sass_delete_options (struct Sass_Options * options)
620
+ {
621
+ sass_clear_options (options); free (options);
622
+ }
623
+
590
624
// Deallocate all associated memory with file context
591
625
void ADDCALL sass_delete_file_context (struct Sass_File_Context * ctx)
592
626
{
0 commit comments