Просмотр исходного кода

auth_identity: add missing error handling for allocation errors, convert to memory log macros

Pantelis Kolatsis 2 лет назад
Родитель
Сommit
e8520177f6

+ 1 - 2
src/modules/auth_identity/auth_dynstr.c

@@ -47,8 +47,7 @@ int initdynstr(dynstr *sout, int isize)
 	memset(sout,0,sizeof(*sout));
 	memset(sout,0,sizeof(*sout));
 	getstr_dynstr(sout).s=pkg_malloc(isize);
 	getstr_dynstr(sout).s=pkg_malloc(isize);
 	if (!getstr_dynstr(sout).s) {
 	if (!getstr_dynstr(sout).s) {
-		LOG(L_WARN,
-			"AUTH_IDENTITY:initdynstr: Not enough memory error\n");
+		PKG_MEM_ERROR;
 		return -1;
 		return -1;
 	}
 	}
 	sout->size=isize;
 	sout->size=isize;

+ 1 - 1
src/modules/auth_identity/auth_hdrs.c

@@ -520,7 +520,7 @@ int append_hf(struct sip_msg* msg, char *str1, enum _hdr_types_t type)
 
 
 	s = (char*)pkg_malloc(len+1);
 	s = (char*)pkg_malloc(len+1);
 	if (!s) {
 	if (!s) {
-		LOG(L_ERR, "AUTH_IDENTITY:append_hf: No memory left\n");
+		PKG_MEM_ERROR;
 		return -1;
 		return -1;
 	}
 	}
 
 

+ 1 - 1
src/modules/auth_identity/auth_http.c

@@ -69,7 +69,7 @@ int download_cer(str *suri, CURL *hcurl)
 	} else {
 	} else {
 		/* +1 for the terminating \0 byte */
 		/* +1 for the terminating \0 byte */
 		if (!(snulledptr=pkg_malloc(suri->len + 1))) {
 		if (!(snulledptr=pkg_malloc(suri->len + 1))) {
-			LOG(L_ERR, "AUTH_IDENTITY:download_cer: Not enough memory error\n");
+			PKG_MEM_ERROR;
 			return -1;
 			return -1;
 		}
 		}
 		memcpy(snulledptr, suri->s, suri->len);
 		memcpy(snulledptr, suri->s, suri->len);

+ 1 - 1
src/modules/auth_identity/auth_identity.c

@@ -216,7 +216,7 @@ static int mod_init(void)
 		return -4;
 		return -4;
 	}
 	}
 	if (!(glb_tcert.scertpem.s=pkg_malloc(CERTIFICATE_LENGTH))) {
 	if (!(glb_tcert.scertpem.s=pkg_malloc(CERTIFICATE_LENGTH))) {
-		LOG(L_ERR, "AUTH_IDENTITY:mod_init: Not enough memory error\n");
+		PKG_MEM_ERROR;
 		return -3;
 		return -3;
 	}
 	}
   	/* some servers don't like requests that are made without a user-agent
   	/* some servers don't like requests that are made without a user-agent

+ 9 - 7
src/modules/auth_identity/auth_tables.c

@@ -64,13 +64,14 @@ int init_table(ttable **ptable,	/* table we'd like to init */
 	int i1;
 	int i1;
 
 
 	if (!(*ptable = (ttable *) shm_malloc(sizeof(**ptable)))) {
 	if (!(*ptable = (ttable *) shm_malloc(sizeof(**ptable)))) {
-		LOG(L_ERR, "AUTH_IDENTITY:init_table: Not enough shared memory error\n");
+		SHM_MEM_ERROR;
 		return -1;
 		return -1;
 	}
 	}
 	memset(*ptable, 0, sizeof(**ptable));
 	memset(*ptable, 0, sizeof(**ptable));
 
 
 	if (!((*ptable)->entries = (tbucket *) shm_malloc(sizeof(tbucket)*ubucknum))) {
 	if (!((*ptable)->entries = (tbucket *) shm_malloc(sizeof(tbucket)*ubucknum))) {
-		LOG(L_ERR, "AUTH_IDENTITY:init_table: Not enough shared memory error\n");
+		SHM_MEM_ERROR;
+		shm_free(*ptable);
 		return -1;
 		return -1;
 	}
 	}
 	memset((*ptable)->entries, 0, sizeof(tbucket)*ubucknum);
 	memset((*ptable)->entries, 0, sizeof(tbucket)*ubucknum);
@@ -121,7 +122,7 @@ static int insert_into_table(ttable *ptable, void *pdata, unsigned int uhash)
 	char bneed2remove=0;
 	char bneed2remove=0;
 
 
 	if (!(pitem=(titem *)shm_malloc(sizeof(*pitem)))) {
 	if (!(pitem=(titem *)shm_malloc(sizeof(*pitem)))) {
-		LOG(L_ERR, "AUTH_IDENTITY:insert_into_table: Not enough shared memory error\n");
+		SHM_MEM_ERROR;
 		return -1;
 		return -1;
 	}
 	}
 
 
@@ -323,7 +324,7 @@ static int str_duplicate(str* _d, str* _s)
 
 
 	_d->s = (char *)shm_malloc(sizeof(char)*(_s->len));
 	_d->s = (char *)shm_malloc(sizeof(char)*(_s->len));
 	if (!_d->s) {
 	if (!_d->s) {
-		LOG(L_ERR, "AUTH_IDENTITY:str_duplicate: No enough shared memory\n");
+		SHM_MEM_ERROR;
 		return -1;
 		return -1;
 	}
 	}
 
 
@@ -408,7 +409,7 @@ int addcert2table(ttable *ptable, tcert_item *pcert)
 	unsigned int uhash;
 	unsigned int uhash;
 
 
 	if (!(pshmcert=(tcert_item *)shm_malloc(sizeof(*pshmcert)))) {
 	if (!(pshmcert=(tcert_item *)shm_malloc(sizeof(*pshmcert)))) {
-		LOG(L_ERR, "AUTH_IDENTITY:addcert2table: No enough shared memory\n");
+		SHM_MEM_ERROR;
 		return -1;
 		return -1;
 	}
 	}
 	memset(pshmcert, 0, sizeof(*pshmcert));
 	memset(pshmcert, 0, sizeof(*pshmcert));
@@ -497,7 +498,7 @@ int proc_cid(ttable *ptable,
 	/* we suppose that this SIP request is not replayed so it doesn't exist in
 	/* we suppose that this SIP request is not replayed so it doesn't exist in
 	   the table so we prepare to insert */
 	   the table so we prepare to insert */
 	if (!(pshmdlg=(tdlg_item *)shm_malloc(sizeof(*pshmdlg)))) {
 	if (!(pshmdlg=(tdlg_item *)shm_malloc(sizeof(*pshmdlg)))) {
-		LOG(L_ERR, "AUTH_IDENTITY:addcid2table: No enough shared memory\n");
+		SHM_MEM_ERROR;
 		return -1;
 		return -1;
 	}
 	}
 	memset(pshmdlg, 0, sizeof(*pshmdlg));
 	memset(pshmdlg, 0, sizeof(*pshmdlg));
@@ -558,7 +559,8 @@ int proc_cid(ttable *ptable,
 	if (!pcid_item) {
 	if (!pcid_item) {
 		/* this is the first request with this call-id */
 		/* this is the first request with this call-id */
 		if (!(pshmcid=(tcid_item *)shm_malloc(sizeof(*pshmcid)))) {
 		if (!(pshmcid=(tcid_item *)shm_malloc(sizeof(*pshmcid)))) {
-			LOG(L_ERR, "AUTH_IDENTITY:addcid2table: No enough shared memory\n");
+			SHM_MEM_ERROR;
+			shm_free(pshmdlg);
 			return -4;
 			return -4;
 		}
 		}
 		memset(pshmcid, 0, sizeof(*pshmcid));
 		memset(pshmcid, 0, sizeof(*pshmcid));