Browse Source

ENGINE-793: refactored bloblist_dup with double pointers.

audit_branch
parent
commit
b54d4b9aa6
1 changed files with 12 additions and 22 deletions
  1. +12
    -22
      src/bloblist.c

+ 12
- 22
src/bloblist.c View File

@ -80,47 +80,37 @@ DYNAMIC_API bloblist_t *bloblist_dup(const bloblist_t *src)
assert(src);
if (src == NULL)
return NULL;
bloblist_t *bloblist = NULL;
// head
char *blob2 = malloc(src->size);
assert(blob2);
if (blob2 == NULL)
goto enomem;
memcpy(blob2, src->value, src->size);
bloblist_t* head_ptr = NULL;
bloblist_t** dst_curr_ptr = &head_ptr;
bloblist = new_bloblist(blob2, src->size, src->mime_type, src->filename);
if (bloblist == NULL)
goto enomem;
blob2 = NULL;
const bloblist_t* src_curr = src;
bloblist_t* src_curr = src->next;
bloblist_t** dst_curr_ptr = &bloblist->next;
char* blob2 = NULL;
// list
while (src_curr) {
for ( ; src_curr; src_curr = src_curr->next, dst_curr_ptr = &((*dst_curr_ptr)->next)) {
blob2 = malloc(src_curr->size);
assert(blob2);
if (blob2 == NULL)
goto enomem;
// This is why we don't calloc
memcpy(blob2, src_curr->value, src_curr->size);
*dst_curr_ptr = new_bloblist(blob2, src_curr->size, src_curr->mime_type, src_curr->filename);
if (*dst_curr_ptr == NULL)
goto enomem;
src_curr = src_curr->next;
dst_curr_ptr = &((*dst_curr_ptr)->next);
}
return bloblist;
if (!head_ptr)
return NULL;
return head_ptr;
enomem:
free(blob2);
free_bloblist(bloblist);
free_bloblist(head_ptr);
return NULL;
}


Loading…
Cancel
Save