[webkit-dev] PSA: Don't try to hold onto temporaries with references

Adam Barth abarth at webkit.org
Sun Oct 3 02:21:34 PDT 2010


If a function returns a temporary, you probably don't want to hold
onto it with a "const Foo& foo".  The temporary will get deallocated
and then you'll be left with a reference to dead memory, which is bad
new bears:

http://trac.webkit.org/changeset/68984
http://trac.webkit.org/changeset/68985

This kind of thing can be tricky to spot in code reviews because it's
not obvious at the call site whether a function turns a temporary or a
reference to some existing object.

Adam


More information about the webkit-dev mailing list