aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2023-09-20 02:22:44 -0400
committersotech117 <michael_foiani@brown.edu>2023-09-20 02:22:44 -0400
commit35e552ad6843c0e149d2389ed0a92de3d114bbbb (patch)
tree4488780fe9b30b0a9bf43c7ce6c78678f7fe20b5
parent005eaf49da54d72e00400c550664dae9469007dc (diff)
malloc error checking
-rw-r--r--snowcast_server_concurrent.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/snowcast_server_concurrent.c b/snowcast_server_concurrent.c
index bb3eee9..d853507 100644
--- a/snowcast_server_concurrent.c
+++ b/snowcast_server_concurrent.c
@@ -274,6 +274,7 @@ void *send_udp_packet_routine(void *arg) {
int int_port = user_data[user_index].udpPort;
int length = snprintf( NULL, 0, "%d", int_port );
char* port = malloc( length + 1 );
+ if (!port) { perror("malloc"); return (NULL); }
snprintf( port, length + 1, "%d", int_port );
sprintf(port, "%d", int_port);
@@ -703,6 +704,10 @@ void send_announce_reply(int fd, int station_num) {
int len_file_path = strlen(file_path);
char *send_buffer = malloc(len_file_path+2);
+ if (!send_buffer) {
+ perror("malloc");
+ return;
+ }
send_buffer[0] = 3;
send_buffer[1] = len_file_path;
@@ -721,6 +726,10 @@ void send_announce_reply(int fd, int station_num) {
void send_invalid_command_reply(int fd, size_t message_size, char* message) {
char *send_buffer = malloc(message_size+2);
+ if (!send_buffer) {
+ perror("malloc");
+ return;
+ }
// type and payload size
send_buffer[0] = 4;