Skip to content

Temporary values are not destructed in C, e.g. string interpolation leaks memory #26

@yeputons

Description

@yeputons

Consider OpAddAssignString.ci:

		s2 += p + $"{p}" + s; //FAIL: cpp - should work with C++20

gets compiled to

	CiString_Assign(&s2, CiString_Format("%s%s%s%s", s2, p, p, s));

here, the result of CiString_Format is a result of malloc. It's passed to CiString_Assign and abandoned afterwards, leaking memory. This does not happen in C++ because temporary values are automatically destructed in C++, including std::string.

I assume there may be other instances where temporary objects are created and not immediately stored into variables.

Metadata

Metadata

Assignees

Labels

CbugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions