| 84 | } |
| 85 | |
| 86 | htable_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 | |
| 123 | error: |
| 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 | |
| 141 | ua_pres_t* search_htable(ua_pres_t* pres, unsigned int hash_code) |
| 142 | { |
no test coverage detected