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

Function do_duplicate_rr

parser/parse_rr.c:267–331  ·  view source on GitHub ↗

* Duplicate a single rr_t structure using pkg_malloc or shm_malloc */

Source from the content-addressed store, hash-verified

265 * Duplicate a single rr_t structure using pkg_malloc or shm_malloc
266 */
267static inline int do_duplicate_rr(rr_t** _new, rr_t* _r, int _shm, int _first)
268{
269 int len, ret;
270 rr_t* res, *prev, *it;
271
272 if (!_new || !_r) {
273 LM_ERR("invalid parameter value\n");
274 return -1;
275 }
276 prev = NULL;
277 *_new = NULL;
278 it = _r;
279 while(it)
280 {
281 if (it->params) {
282 len = it->params->name.s + it->params->len - it->nameaddr.name.s;
283 } else {
284 len = it->nameaddr.len;
285 }
286
287 if (_shm) res = shm_malloc(sizeof(rr_t) + len);
288 else res = pkg_malloc(sizeof(rr_t) + len);
289 if (!res) {
290 LM_ERR("no shm memory left\n");
291 goto error;
292 }
293 memcpy(res, it, sizeof(rr_t));
294
295 res->nameaddr.name.s = (char*)res + sizeof(rr_t);
296 memcpy(res->nameaddr.name.s, it->nameaddr.name.s, len);
297
298 if (_shm) {
299 ret = shm_duplicate_params(&res->params, it->params);
300 } else {
301 ret = duplicate_params(&res->params, it->params);
302 }
303
304 if (ret < 0) {
305 LM_ERR("failed to duplicate parameters\n");
306 if (_shm) shm_free(res);
307 else pkg_free(res);
308 goto error;
309 }
310
311 xlate_pointers(it, res);
312
313 res->next=NULL;
314 if(*_new==NULL)
315 *_new = res;
316
317 if (_first)
318 return 0;
319
320 if(prev)
321 prev->next = res;
322 prev = res;
323 it = it->next;
324 }

Callers 2

duplicate_rrFunction · 0.85
shm_duplicate_rrFunction · 0.85

Calls 7

shm_mallocFunction · 0.85
shm_duplicate_paramsFunction · 0.85
duplicate_paramsFunction · 0.85
shm_freeFunction · 0.85
xlate_pointersFunction · 0.85
shm_free_rrFunction · 0.85
free_rrFunction · 0.85

Tested by

no test coverage detected