88#include <arpa/inet.h>
99#include <cupsfilters/ipp.h>
1010
11-
1211#define MAX_ADDRESSES 10
1312#define _CUPS_NO_DEPRECATED 1
1413
@@ -1455,6 +1454,12 @@ void print_socket(PrinterCUPS *p, int num_settings, GVariant *settings, char *jo
14551454
14561455 // Create base directories
14571456 char * home = getenv ("HOME" );
1457+ if (home == NULL ) {
1458+ logwarn ("HOME environment variable not set\n" );
1459+ close (socket_fd );
1460+ cupsFreeOptions (num_options , options );
1461+ return ;
1462+ }
14581463 char base_dir [256 ];
14591464 char socket_dir [512 ];
14601465
@@ -1493,11 +1498,13 @@ void print_socket(PrinterCUPS *p, int num_settings, GVariant *settings, char *jo
14931498 if (bind (socket_fd , (struct sockaddr * )& server_addr , sizeof (server_addr )) == -1 ){
14941499 logwarn ("Bind failed" );
14951500 close (socket_fd );
1501+ cupsFreeOptions (num_options , options );
14961502 return ;
14971503 }
14981504 if (listen (socket_fd , 1 ) == -1 ) {
14991505 logwarn ("listen failed" );
15001506 close (socket_fd );
1507+ cupsFreeOptions (num_options , options );
15011508 return ;
15021509 }
15031510
@@ -1506,6 +1513,7 @@ void print_socket(PrinterCUPS *p, int num_settings, GVariant *settings, char *jo
15061513 num_options , options , 1 ) != HTTP_STATUS_CONTINUE ) {
15071514 logwarn ("could not start document: %s\n" , cupsLastErrorString ());
15081515 close (socket_fd );
1516+ cupsFreeOptions (num_options , options );
15091517 return ;
15101518 }
15111519
@@ -1521,6 +1529,8 @@ void print_socket(PrinterCUPS *p, int num_settings, GVariant *settings, char *jo
15211529 if (pthread_create (& thread , NULL , print_data_thread , thread_data ) != 0 ) {
15221530 logwarn ("Error creating thread" );
15231531 close (socket_fd );
1532+ cupsFreeOptions (num_options , options );
1533+ g_free (thread_data );
15241534 } else {
15251535 // Detach the thread to allow it to run independently
15261536 pthread_detach (thread );
0 commit comments