Browse Source

use a static size buffer for the file path name

Helmut Pozimski 4 years ago
parent
commit
87113aba2b
1 changed files with 2 additions and 7 deletions
  1. 2 7
      src/main.c

+ 2 - 7
src/main.c

@@ -20,6 +20,7 @@
 #include "wavfile.h"
 
 #define BUF_SIZE 1558
+#define MAX_PATH_LEN 255
 
 typedef struct {
 	uint32_t sample_rate;
@@ -32,7 +33,7 @@ typedef struct {
 } sync_ack;
 
 /* global variables */
-char * filepath;
+char filepath[MAX_PATH_LEN + 30];
 uint8_t file_closed = -1;
 wavfile * file;
 int sock;
@@ -49,7 +50,6 @@ static void signal_handler(int signal) {
 	if (!file_closed) {
 		wavfile_close(file);
 	}
-	free(filepath);
 	tcpserver_stop(sock);
 	exit(EXIT_SUCCESS);
 }
@@ -123,11 +123,6 @@ int main(int argc, char **argv) {
 		syslog(LOG_ERR, "Failed to start TCP server\n");
 		return EXIT_FAILURE;
 	}
-	filepath = malloc(strlen(directory) + 1 + 29);
-	if (filepath == NULL) {
-		syslog(LOG_ERR, "Error allocating memory for file path\n");
-		return EXIT_FAILURE;
-	}
 	namelen = sizeof(client);
 	while (1) {
 		conn = accept(sock, (struct sockaddr *)&client, &namelen);