git:master:617e8c40: acc_diameter: few updates to make cleaner avp handling

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

git:master:617e8c40: acc_diameter: few updates to make cleaner avp handling

Daniel-Constantin Mierla-6
Module: kamailio
Branch: master
Commit: 617e8c40608c5e2ac97dd4b39d9ab739a779b9bb
URL: https://github.com/kamailio/kamailio/commit/617e8c40608c5e2ac97dd4b39d9ab739a779b9bb

Author: Daniel-Constantin Mierla <[hidden email]>
Committer: Daniel-Constantin Mierla <[hidden email]>
Date: 2017-08-11T09:46:29+02:00

acc_diameter: few updates to make cleaner avp handling

---

Modified: src/modules/acc_diameter/diam_avp.c
Modified: src/modules/acc_diameter/diam_message.c
Modified: src/modules/acc_diameter/diam_tcp.c

---

Diff:  https://github.com/kamailio/kamailio/commit/617e8c40608c5e2ac97dd4b39d9ab739a779b9bb.diff
Patch: https://github.com/kamailio/kamailio/commit/617e8c40608c5e2ac97dd4b39d9ab739a779b9bb.patch

---

diff --git a/src/modules/acc_diameter/diam_avp.c b/src/modules/acc_diameter/diam_avp.c
index f9d98dc61d..2ea5a577fa 100644
--- a/src/modules/acc_diameter/diam_avp.c
+++ b/src/modules/acc_diameter/diam_avp.c
@@ -107,7 +107,7 @@ AAA_AVP*  AAACreateAVP(
  size_t length,
  AVPDataStatus data_status)
 {
- AAA_AVP *avp;
+ AAA_AVP *avp = NULL;
 
  /* first check the params */
  if( data==0 || length==0) {
@@ -146,7 +146,8 @@ AAA_AVP*  AAACreateAVP(
 
  return avp;
 error:
- LM_ERR("no more free memoryfor a new AVP!\n");
+ LM_ERR("no more free memory for a new AVP!\n");
+ if(avp) ad_free(avp);
  return 0;
 }
 
diff --git a/src/modules/acc_diameter/diam_message.c b/src/modules/acc_diameter/diam_message.c
index 07b441d969..614318b26d 100644
--- a/src/modules/acc_diameter/diam_message.c
+++ b/src/modules/acc_diameter/diam_message.c
@@ -293,11 +293,15 @@ AAAMessage* AAATranslateMessage( unsigned char* source, unsigned int sourceLen,
  /* create the AVP */
  avp = AAACreateAVP( avp_code, avp_flags, avp_vendorID, (char*)ptr,
  avp_data_len, AVP_DONT_FREE_DATA);
- if (!avp)
+ if (!avp) {
+ LM_ERR("failed to create aaa avp\n");
  goto error;
+ }
 
  /* link the avp into aaa message to the end */
- AAAAddAVPToMessage( msg, avp, msg->avpList.tail);
+ if(AAAAddAVPToMessage( msg, avp, msg->avpList.tail)!= AAA_ERR_SUCCESS) {
+ LM_ERR("failed to add aaa avp to message\n");
+ goto error; }
 
  ptr += to_32x_len( avp_data_len );
  }
diff --git a/src/modules/acc_diameter/diam_tcp.c b/src/modules/acc_diameter/diam_tcp.c
index 724383d682..77525479c5 100644
--- a/src/modules/acc_diameter/diam_tcp.c
+++ b/src/modules/acc_diameter/diam_tcp.c
@@ -48,13 +48,13 @@
 /*! \brief TCP connection setup */
 int init_mytcp(char* host, int port)
 {
- int sockfd;
+ int sfd;
  struct sockaddr_in serv_addr;
  struct hostent *server;
 
- sockfd = socket(PF_INET, SOCK_STREAM, 0);
+ sfd = socket(PF_INET, SOCK_STREAM, 0);
 
- if (sockfd < 0)
+ if (sfd < 0)
  {
  LM_ERR("failed to create the socket\n");
  return -1;
@@ -64,6 +64,7 @@ int init_mytcp(char* host, int port)
  if (server == NULL)
  {
  LM_ERR("failed to find the host\n");
+ close(sfd);
  return -1;
  }
 
@@ -73,18 +74,19 @@ int init_mytcp(char* host, int port)
  server->h_length);
  serv_addr.sin_port = htons(port);
 
- if (connect(sockfd, (const struct sockaddr *)&serv_addr,
+ if (connect(sfd, (const struct sockaddr *)&serv_addr,
  sizeof(serv_addr)) < 0)
  {
  LM_ERR("failed to connec to the DIAMETER client\n");
+ close(sfd);
  return -1;
  }
 
- return sockfd;
+ return sfd;
 }
 
 /*! \brief send a message over an already opened TCP connection */
-int tcp_send_recv(int sockfd, char* buf, int len, rd_buf_t* rb,
+int tcp_send_recv(int sfd, char* buf, int len, rd_buf_t* rb,
  unsigned int waited_id)
 {
  int n, number_of_tries;
@@ -97,7 +99,7 @@ int tcp_send_recv(int sockfd, char* buf, int len, rd_buf_t* rb,
  unsigned int m_id;
 
  /* try to write the message to the Diameter client */
- while( (n=write(sockfd, buf, len))==-1 )
+ while( (n=write(sfd, buf, len))==-1 )
  {
  if (errno==EINTR)
  continue;
@@ -116,26 +118,26 @@ int tcp_send_recv(int sockfd, char* buf, int len, rd_buf_t* rb,
 
  /* Initialize the set of active sockets. */
  FD_ZERO (&active_fd_set);
- FD_SET (sockfd, &active_fd_set);
+ FD_SET (sfd, &active_fd_set);
  number_of_tries = 0;
 
  while(number_of_tries<MAX_TRIES)
  {
  read_fd_set = active_fd_set;
- if (select (sockfd+1, &read_fd_set, NULL, NULL, &tv) < 0)
+ if (select (sfd+1, &read_fd_set, NULL, NULL, &tv) < 0)
  {
  LM_ERR("select function failed\n");
  return AAA_ERROR;
  }
 
- /* if (!FD_ISSET (sockfd, &read_fd_set))
+ /* if (!FD_ISSET (sfd, &read_fd_set))
  {
  LM_ERR("no response received\n");
  // return AAA_ERROR;
  }
  */ /* Data arriving on a already-connected socket. */
  reset_read_buffer(rb);
- switch( do_read(sockfd, rb) )
+ switch( do_read(sfd, rb) )
  {
  case CONN_ERROR:
  LM_ERR("failed to read from socket\n");


_______________________________________________
Kamailio (SER) - Development Mailing List
[hidden email]
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev
Loading...