Skip to content

Commit 0b2a870

Browse files
committed
Replace heap allocation to stack array for simplicity
1 parent 6d6b47b commit 0b2a870

1 file changed

Lines changed: 8 additions & 14 deletions

File tree

examples/c/builtin_echo.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,16 @@ int login(char *token, size_t *token_len) {
104104

105105
int main() {
106106
int ret = 0;
107-
char *token = (char *)calloc(BUFFER_SIZE, sizeof(char));
108-
size_t token_len = BUFFER_SIZE;
109-
char *serialized_response = (char *)calloc(BUFFER_SIZE, sizeof(char));
110-
char *function_id = (char *)calloc(BUFFER_SIZE, sizeof(char));
111-
char *serialized_request = (char *)calloc(BUFFER_SIZE, sizeof(char));
112-
char *task_result = (char *)calloc(BUFFER_SIZE, sizeof(char));
113-
char *task_id = (char *)calloc(BUFFER_SIZE, sizeof(char));
107+
108+
char token[BUFFER_SIZE] = {0};
109+
char serialized_response[BUFFER_SIZE] = {0};
110+
char function_id[BUFFER_SIZE] = {0};
111+
char serialized_request[BUFFER_SIZE] = {0};
112+
char task_result[BUFFER_SIZE] = {0};
113+
char task_id[BUFFER_SIZE] = {0};
114114

115115
/* Login. */
116+
size_t token_len = BUFFER_SIZE;
116117
ret = login(token, &token_len);
117118
if (ret != 0) {
118119
fprintf(stderr, "[-] Failed to login.\n");
@@ -188,12 +189,5 @@ int main() {
188189
fprintf(stderr, "[-] Failed to close the frontend service client.\n");
189190
}
190191

191-
free(token);
192-
free(serialized_response);
193-
free(function_id);
194-
free(serialized_request);
195-
free(task_id);
196-
free(task_result);
197-
198192
return ret;
199193
}

0 commit comments

Comments
 (0)