Skip to content

Commit

Permalink
jsonrpcs: safety vars init and release checks
Browse files Browse the repository at this point in the history
(cherry picked from commit 080bffe)
  • Loading branch information
miconda committed Aug 30, 2017
1 parent 3850fe0 commit 39956a5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/modules/jsonrpcs/jsonrpcs_mod.c
Expand Up @@ -755,6 +755,7 @@ static int jsonrpc_struct_add(srjson_t *jnode, char* fmt, ...)
while(*fmt) {
mname.s = va_arg(ap, char*);
mname.len = (mname.s?strlen(mname.s):0);
if(mname.s==NULL) mname.s = "";

if (*fmt == '{' || *fmt == '[') {
void_ptr = va_arg(ap, void**);
Expand Down
10 changes: 6 additions & 4 deletions src/modules/jsonrpcs/jsonrpcs_sock.c
Expand Up @@ -388,9 +388,9 @@ int jsonrpc_dgram_init_server(jsonrpc_dgram_sockaddr_t *addr,

return 0;
err_both:
close(socks->tx_sock);
if(socks->tx_sock>=0) close(socks->tx_sock);
err_rx:
close(socks->rx_sock);
if(socks->rx_sock>=0) close(socks->rx_sock);
return -1;
}

Expand Down Expand Up @@ -528,15 +528,17 @@ static int jsonrpc_dgram_send_data(int fd, char* buf, unsigned int len,
{
int n;
unsigned int optlen = sizeof(int);
int optval;
int optval = 0;

if(len == 0 || tolen ==0)
return -1;

/*LM_DBG("destination address length is %i\n", tolen);*/
n=sendto(fd, buf, len, 0, to, tolen);
if(n!=len) {
getsockopt(fd, SOL_SOCKET, SO_SNDBUF, (int*)&optval, &optlen);
if(getsockopt(fd, SOL_SOCKET, SO_SNDBUF, (int*)&optval, &optlen)==-1) {
LM_ERR("getsockopt failed\n");
}
LM_ERR("failed to send the response - ret: %d, len: %d (%d),"
" err: %d - %s)\n",
n, len, optval, errno, strerror(errno));
Expand Down

0 comments on commit 39956a5

Please sign in to comment.