Skip to content

Commit

Permalink
Adding error handling (jerryscript-project#1097)
Browse files Browse the repository at this point in the history
- adding error handling for iotjs_file_read()
- changing free()->iotjs_buffer_release()

IoT.js-DCO-1.0-Signed-off-by: Haesik, Jun [email protected]
  • Loading branch information
haesik authored and yichoi committed Aug 8, 2017
1 parent 7e22f19 commit eeedc31
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/iotjs_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@

iotjs_string_t iotjs_file_read(const char* path) {
FILE* file = fopen(path, "rb");
IOTJS_ASSERT(file != NULL);
if (file == NULL) {
iotjs_string_t empty_content = iotjs_string_create();
return empty_content;
}

fseek(file, 0, SEEK_END);
long ftell_ret = ftell(file);
Expand Down
6 changes: 3 additions & 3 deletions src/platform/linux/iotjs_module_pwm-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ bool iotjs_pwm_set_period(iotjs_pwm_t* pwm) {
if (snprintf(buf, sizeof(buf), "%d", value) > 0) {
result = iotjs_systemio_open_write_close(devicePath, buf);
}
free(devicePath);
iotjs_buffer_release(devicePath);
}
}
return result;
Expand Down Expand Up @@ -169,7 +169,7 @@ bool iotjs_pwm_set_dutycycle(iotjs_pwm_t* pwm) {
}

result = iotjs_systemio_open_write_close(devicePath, buf);
free(devicePath);
iotjs_buffer_release(devicePath);
}
}
return result;
Expand All @@ -195,7 +195,7 @@ bool iotjs_pwm_set_enable(iotjs_pwm_t* pwm) {
}

result = iotjs_systemio_open_write_close(devicePath, buf);
free(devicePath);
iotjs_buffer_release(devicePath);
}
return result;
}
Expand Down

0 comments on commit eeedc31

Please sign in to comment.