Commit 4abc7ddd by Adeel

Code: Mitigates chances of memory leaks.

parent 739cc088
...@@ -31,34 +31,28 @@ void ExtractOptions(Local<Object> options, void* cptr, sass_context_wrapper* ctx ...@@ -31,34 +31,28 @@ void ExtractOptions(Local<Object> options, void* cptr, sass_context_wrapper* ctx
ctx_w->errorCallback = new NanCallback(errorCallback); ctx_w->errorCallback = new NanCallback(errorCallback);
} }
struct Sass_Options* sass_options;
if (isFile) { if (isFile) {
struct Sass_File_Context* fctx = (struct Sass_File_Context*) cptr; struct Sass_File_Context* fctx = (struct Sass_File_Context*) cptr;
struct Sass_Context* ctx = sass_file_context_get_context(fctx); struct Sass_Context* ctx = sass_file_context_get_context(fctx);
struct Sass_Options* sass_options = sass_context_get_options(ctx); sass_options = sass_context_get_options(ctx);
sass_option_set_output_path(sass_options, CreateString(options->Get(NanNew("outFile"))));
sass_option_set_image_path(sass_options, CreateString(options->Get(NanNew("imagePath"))));
sass_option_set_output_style(sass_options, (Sass_Output_Style)options->Get(NanNew("style"))->Int32Value());
sass_option_set_source_comments(sass_options, source_comments = options->Get(NanNew("comments"))->BooleanValue());
sass_option_set_omit_source_map_url(sass_options, options->Get(NanNew("omitSourceMapUrl"))->BooleanValue());
sass_option_set_source_map_file(sass_options, CreateString(options->Get(NanNew("sourceMap"))));
sass_option_set_include_path(sass_options, CreateString(options->Get(NanNew("paths"))));
sass_option_set_precision(sass_options, options->Get(NanNew("precision"))->Int32Value());
} else { } else {
struct Sass_Data_Context* dctx = (struct Sass_Data_Context*) cptr; struct Sass_Data_Context* dctx = (struct Sass_Data_Context*) cptr;
struct Sass_Context* ctx = sass_data_context_get_context(dctx); struct Sass_Context* ctx = sass_data_context_get_context(dctx);
struct Sass_Options* sass_options = sass_context_get_options(ctx); sass_options = sass_context_get_options(ctx);
sass_option_set_output_path(sass_options, CreateString(options->Get(NanNew("outFile"))));
sass_option_set_is_indented_syntax_src(sass_options, options->Get(NanNew("indentedSyntax"))->BooleanValue()); sass_option_set_is_indented_syntax_src(sass_options, options->Get(NanNew("indentedSyntax"))->BooleanValue());
sass_option_set_image_path(sass_options, CreateString(options->Get(NanNew("imagePath"))));
sass_option_set_output_style(sass_options, (Sass_Output_Style)options->Get(NanNew("style"))->Int32Value());
sass_option_set_source_comments(sass_options, source_comments = options->Get(NanNew("comments"))->BooleanValue());
sass_option_set_omit_source_map_url(sass_options, options->Get(NanNew("omitSourceMapUrl"))->BooleanValue());
sass_option_set_source_map_file(sass_options, CreateString(options->Get(NanNew("sourceMap"))));
sass_option_set_include_path(sass_options, CreateString(options->Get(NanNew("paths"))));
sass_option_set_precision(sass_options, options->Get(NanNew("precision"))->Int32Value());
} }
sass_option_set_output_path(sass_options, CreateString(options->Get(NanNew("outFile"))));
sass_option_set_image_path(sass_options, CreateString(options->Get(NanNew("imagePath"))));
sass_option_set_output_style(sass_options, (Sass_Output_Style)options->Get(NanNew("style"))->Int32Value());
sass_option_set_source_comments(sass_options, source_comments = options->Get(NanNew("comments"))->BooleanValue());
sass_option_set_omit_source_map_url(sass_options, options->Get(NanNew("omitSourceMapUrl"))->BooleanValue());
sass_option_set_source_map_file(sass_options, CreateString(options->Get(NanNew("sourceMap"))));
sass_option_set_include_path(sass_options, CreateString(options->Get(NanNew("paths"))));
sass_option_set_precision(sass_options, options->Get(NanNew("precision"))->Int32Value());
} }
void FillStatsObj(Handle<Object> stats, Sass_Context* ctx) { void FillStatsObj(Handle<Object> stats, Sass_Context* ctx) {
...@@ -149,7 +143,6 @@ NAN_METHOD(Render) { ...@@ -149,7 +143,6 @@ NAN_METHOD(Render) {
int status = uv_queue_work(uv_default_loop(), &ctx_w->request, compile_it, (uv_after_work_cb)MakeCallback); int status = uv_queue_work(uv_default_loop(), &ctx_w->request, compile_it, (uv_after_work_cb)MakeCallback);
assert(status == 0); assert(status == 0);
// free(source_string);
NanReturnUndefined(); NanReturnUndefined();
} }
...@@ -165,7 +158,6 @@ NAN_METHOD(RenderSync) { ...@@ -165,7 +158,6 @@ NAN_METHOD(RenderSync) {
ExtractOptions(options, dctx, NULL, false); ExtractOptions(options, dctx, NULL, false);
compile_data(dctx); compile_data(dctx);
FillStatsObj(options->Get(NanNew("stats"))->ToObject(), ctx); FillStatsObj(options->Get(NanNew("stats"))->ToObject(), ctx);
// free(source_string);
if (sass_context_get_error_status(ctx) == 0) { if (sass_context_get_error_status(ctx) == 0) {
Local<String> output = NanNew<String>(sass_context_get_output_string(ctx)); Local<String> output = NanNew<String>(sass_context_get_output_string(ctx));
...@@ -196,7 +188,7 @@ NAN_METHOD(RenderFile) { ...@@ -196,7 +188,7 @@ NAN_METHOD(RenderFile) {
int status = uv_queue_work(uv_default_loop(), &ctx_w->request, compile_it, (uv_after_work_cb)MakeCallback); int status = uv_queue_work(uv_default_loop(), &ctx_w->request, compile_it, (uv_after_work_cb)MakeCallback);
assert(status == 0); assert(status == 0);
// free(input_path); free(input_path);
NanReturnUndefined(); NanReturnUndefined();
} }
...@@ -213,7 +205,7 @@ NAN_METHOD(RenderFileSync) { ...@@ -213,7 +205,7 @@ NAN_METHOD(RenderFileSync) {
compile_file(fctx); compile_file(fctx);
FillStatsObj(options->Get(NanNew("stats"))->ToObject(), ctx); FillStatsObj(options->Get(NanNew("stats"))->ToObject(), ctx);
// free(input_path); free(input_path);
if (sass_context_get_error_status(ctx) == 0) { if (sass_context_get_error_status(ctx) == 0) {
Local<String> output = NanNew<String>(sass_context_get_output_string(ctx)); Local<String> output = NanNew<String>(sass_context_get_output_string(ctx));
......
...@@ -26,16 +26,10 @@ extern "C" { ...@@ -26,16 +26,10 @@ extern "C" {
} }
void free_data_context(struct Sass_Data_Context* dctx) { void free_data_context(struct Sass_Data_Context* dctx) {
// delete[] dctx->source_string;
// delete[] dctx->options.include_paths;
// delete[] dctx->options.image_path;
sass_delete_data_context(dctx); sass_delete_data_context(dctx);
} }
void free_file_context(struct Sass_File_Context* fctx) { void free_file_context(struct Sass_File_Context* fctx) {
// delete[] fctx->input_path;
// delete[] fctx->options.include_paths;
// delete[] fctx->options.image_path;
sass_delete_file_context(fctx); sass_delete_file_context(fctx);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment