| 78 | |
| 79 | |
| 80 | sbtable_t new_shtable(int hash_size){ |
| 81 | sbtable_t htable= NULL; |
| 82 | int i, j; |
| 83 | |
| 84 | i = 0; |
| 85 | htable= (subs_table_t*)shm_malloc(hash_size* sizeof(subs_table_t)); |
| 86 | if(htable== NULL) |
| 87 | { |
| 88 | LM_ERR("--------------------------------------------------no more shm memory\n"); |
| 89 | goto error; |
| 90 | } |
| 91 | memset(htable, 0, hash_size* sizeof(subs_table_t)); |
| 92 | |
| 93 | for(i= 0; i< hash_size; i++) |
| 94 | { |
| 95 | if(lock_init(&htable[i].lock)== 0) |
| 96 | { |
| 97 | LM_ERR("initializing lock [%d]\n", i); |
| 98 | goto error; |
| 99 | } |
| 100 | htable[i].entries= (struct sm_subscriber*)shm_malloc(sizeof(struct sm_subscriber)); |
| 101 | if(htable[i].entries== NULL) |
| 102 | { |
| 103 | lock_destroy(&htable[i].lock); |
| 104 | LM_ERR("--------------------------------------------------no more shm memory\n"); |
| 105 | } |
| 106 | memset(htable[i].entries, 0, sizeof(struct sm_subscriber)); |
| 107 | htable[i].entries->next= NULL; |
| 108 | } |
| 109 | |
| 110 | return htable; |
| 111 | error: |
| 112 | if(htable){ |
| 113 | for(j=0; j< i; j++){ |
| 114 | lock_destroy(&htable[j].lock); |
| 115 | shm_free(htable[j].entries); |
| 116 | } |
| 117 | shm_free(htable); |
| 118 | } |
| 119 | return NULL; |
| 120 | } |
| 121 | |
| 122 | |
| 123 |
no test coverage detected