Skip to content

Commit

Permalink
Problem: setting anchors manually before resolution
Browse files Browse the repository at this point in the history
Getting an error indicating free() trying free what was not allocated:

```
malloc: *** error for object 0x16b03e550: pointer being freed was not allocated
```

Solution: ensure anchoring setup doesn't erroneously point to non-allocated data

In the original code, data_copy was getting a new pointer allocation,
and that was making tthe code below assume `text` is malloc'd which is
not necessarily true.
  • Loading branch information
yrashk authored and pantoniou committed Oct 21, 2023
1 parent 7f7be36 commit 618589b
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/lib/fy-doc.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,13 @@ static int fy_document_set_anchor_internal(struct fy_document *fyd, struct fy_no
fyd_error_check(fyd, data_copy, err_out,
"malloc() failed");
memcpy(data_copy, text, len);
fyi = fy_input_from_malloc_data(data_copy, len, &handle, true);
} else if (malloced)
data_copy = (char *)text;
else
data_copy = NULL;

if (data_copy)
fyi = fy_input_from_malloc_data((void *)text, len, &handle, true);
fyi = fy_input_from_malloc_data(data_copy, len, &handle, true);
else
fyi = fy_input_from_data(text, len, &handle, true);
fyd_error_check(fyd, fyi, err_out,
Expand Down

0 comments on commit 618589b

Please sign in to comment.