Problem was that replace_dynstr_append_mem() assumed strings are null terminated which is not always the case.
Attach a file by drag & drop or click to upload