Skip to content

Commit 3f91324

Browse files
committed
proper functions exit, deallocating memory in main files
1 parent 04b75d1 commit 3f91324

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

tests/tools/TestApp/rx_app.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ int main(int argc, char *argv[]) {
5151
mesh_delete_connection(&connection);
5252
mesh_delete_client(&client);
5353
printf("[RX] Shutdown completed exiting\n");
54-
54+
free((char*)client_cfg);
55+
free((char*)conn_cfg);
5556
return 0;
5657
}

tests/tools/TestApp/src/mcm.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ int mcm_send_video_frames(MeshConnection *connection, MeshClient *client, FILE *
1818
MeshBuffer *buf;
1919
if (file == NULL) {
2020
printf("[TX] Failed to serialize video: file is null \n");
21-
exit(1);
21+
err = 1;
22+
return err;
2223
}
2324

2425
unsigned char frame_num = 0;
@@ -29,27 +30,30 @@ int mcm_send_video_frames(MeshConnection *connection, MeshClient *client, FILE *
2930
err = mesh_get_buffer(connection, &buf);
3031
if (err) {
3132
printf("[TX] Failed to get buffer: %s (%d)\n", mesh_err2str(err), err);
32-
exit(err);
33+
err = 2;
34+
return err;
3335
}
3436
read_size = fread(buf->payload_ptr, 1, buf->payload_len, file);
3537
if (read_size == 0) {
36-
exit(2);
38+
err = 2;
39+
return err;
3740
}
3841

3942
/* Send the buffer */
4043
printf("[TX] Sending frame: %d\n", ++frame_num);
4144
err = mesh_put_buffer(&buf);
4245
if (err) {
4346
printf("[TX] Failed to put buffer: %s (%d)\n", mesh_err2str(err), err);
44-
exit(err);
47+
err = 2;
48+
return err;
4549
}
4650

4751
/* Temporary implementation for pacing */
4852
/* TODO: Implement pacing calculation */
4953
usleep(40000);
5054
}
5155
printf("[TX] data sent successfully \n");
52-
return err;
56+
return 0;
5357
}
5458

5559
void read_data_in_loop(MeshConnection *connection, const char *filename) {
@@ -69,20 +73,18 @@ void read_data_in_loop(MeshConnection *connection, const char *filename) {
6973
err = mesh_get_buffer_timeout(connection, &buf, timeout);
7074
if (err == MESH_ERR_CONN_CLOSED) {
7175
printf("[RX] Connection closed\n");
72-
exit(err);
76+
7377
}
7478
printf("[RX] Fetched mesh data buffer\n");
7579
if (err) {
7680
printf("[RX] Failed to get buffer: %s (%d)\n", mesh_err2str(err), err);
77-
exit(err);
7881
}
7982
/* Process the received user data */
8083
buffer_to_file(out, buf);
8184

8285
err = mesh_put_buffer(&buf);
8386
if (err) {
8487
printf("[RX] Failed to put buffer: %s (%d)\n", mesh_err2str(err), err);
85-
exit(err);
8688
}
8789
printf("[RX] Frame: %d\n", ++frame);
8890
fclose(out);
@@ -96,7 +98,6 @@ void buffer_to_file(FILE *file, MeshBuffer *buf) {
9698
return;
9799
}
98100
// Write the buffer to the file
99-
unsigned int *temp_buf = buf->payload_ptr;
100101
fwrite(buf->payload_ptr, buf->payload_len, 1, file);
101102
printf("[RX] Saving buffer data to a file\n");
102103
}

tests/tools/TestApp/tx_app.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,7 @@ int main(int argc, char **argv) {
5656
mesh_delete_connection(&connection);
5757
mesh_delete_client(&client);
5858
printf("[TX] Shutdown completed. Exiting\n");
59+
free((char*)client_cfg);
60+
free((char*)conn_cfg);
5961
return 0;
6062
}

0 commit comments

Comments
 (0)