Преглед изворни кода

cdp: safety check closing fd for error cases

Daniel-Constantin Mierla пре 2 година
родитељ
комит
631aab425e
2 измењених фајлова са 6 додато и 2 уклоњено
  1. 2 0
      src/modules/cdp/cdp_mod.c
  2. 4 2
      src/modules/cdp/receiver.c

+ 2 - 0
src/modules/cdp/cdp_mod.c

@@ -78,7 +78,9 @@ static int w_cdp_has_app2(sip_msg_t *msg, char *vendor, char *appid);
 static int w_cdp_has_app(sip_msg_t *msg, char *appid, char *param);
 static int w_cdp_has_app(sip_msg_t *msg, char *appid, char *param);
 
 
 
 
+/* clang-format off */
 #define EXP_FUNC(NAME) {#NAME, (cmd_function)NAME, NO_SCRIPT, 0, 0}
 #define EXP_FUNC(NAME) {#NAME, (cmd_function)NAME, NO_SCRIPT, 0, 0}
+/* clang-format on */
 
 
 /**
 /**
  * Exported functions. This is the API available for use from other modules.
  * Exported functions. This is the API available for use from other modules.

+ 4 - 2
src/modules/cdp/receiver.c

@@ -161,8 +161,10 @@ static void close_send_pipe(serviced_peer_t *sp)
 {
 {
 	int tmp;
 	int tmp;
 	if(sp->send_pipe_name.s) {
 	if(sp->send_pipe_name.s) {
-		close(sp->send_pipe_fd);
-		close(sp->send_pipe_fd_out);
+		if(sp->send_pipe_fd >= 0)
+			close(sp->send_pipe_fd);
+		if(sp->send_pipe_fd_out >= 0)
+			close(sp->send_pipe_fd_out);
 		tmp = remove(sp->send_pipe_name.s);
 		tmp = remove(sp->send_pipe_name.s);
 		if(tmp == -1) {
 		if(tmp == -1) {
 			LM_ERR("could not remove send pipe\n");
 			LM_ERR("could not remove send pipe\n");