MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / new_htable

Function new_htable

modules/pua/hash.c:86–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84}
85
86htable_t* new_htable(void)
87{
88 htable_t* H= NULL;
89 int i= 0, j;
90
91 H= (htable_t*)shm_malloc(sizeof(htable_t));
92 if(H== NULL)
93 {
94 LM_ERR("No more memory\n");
95 return NULL;
96 }
97 memset(H, 0, sizeof(htable_t));
98
99 H->p_records= (hash_entry_t*)shm_malloc(HASH_SIZE* sizeof(hash_entry_t));
100 if(H->p_records== NULL)
101 {
102 LM_ERR("No more share memory\n");
103 goto error;
104 }
105
106 for(i=0; i<HASH_SIZE; i++)
107 {
108 if(lock_init(&H->p_records[i].lock)== 0)
109 {
110 LM_CRIT("initializing lock [%d]\n", i);
111 goto error;
112 }
113 H->p_records[i].entity= (ua_pres_t*)shm_malloc(sizeof(ua_pres_t));
114 if(H->p_records[i].entity== NULL)
115 {
116 LM_ERR("No more share memory\n");
117 goto error;
118 }
119 memset(H->p_records[i].entity, 0, sizeof(ua_pres_t));
120 }
121 return H;
122
123error:
124
125 if(H->p_records)
126 {
127 for(j=0; j< i; j++)
128 {
129 if(H->p_records[j].entity)
130 shm_free(H->p_records[j].entity);
131 lock_destroy(&H->p_records[j].lock);
132
133 }
134 shm_free(H->p_records);
135 }
136 shm_free(H);
137 return NULL;
138
139}
140
141ua_pres_t* search_htable(ua_pres_t* pres, unsigned int hash_code)
142{

Callers 1

mod_initFunction · 0.85

Calls 4

shm_mallocFunction · 0.85
lock_initFunction · 0.85
shm_freeFunction · 0.85
lock_destroyFunction · 0.85

Tested by

no test coverage detected