| Bill Allombert on Sun, 27 Aug 2023 15:06:19 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: bug in simplify_shallow |
On Sat, Aug 26, 2023 at 03:47:09PM +0200, Karim Belabas wrote: > You'll see it with valgrind. > > >From the GP code, I can guess what's happening: the lexical variable L > will be destroyed (gunclone) when we leave the user function scope. But > that user function still returns the return value of listput() which is > the element stored in the list. The latter is a 'clone' (as all list > entries), so supposedly safe. The lexical variable destructor breaks > that asumption. > > I don't think the reference count machinery currently in place can > deal with this. Adding a gcopy somewhere should be enough (but slow down > all 'listput' operations...). Don't have time to delve in the C code > right now to confirm this; I'll have a look later if Bill doesn't beat > me to it :-) Well, we could probably change listput (and listinsert) to use the prototype code m. But to be honest I did not remember that listput returned x and it is not explicitly documented, and the implementation is awkward. (the simple, correct implementation would return gcopy of the original x, not a clone of it). Cheers, Bill.