Skip to content

Commit 613d76a

Browse files
committed
Correct memory leak in MediaConstraints
https://bugs.webkit.org/show_bug.cgi?id=167744 <rdar://problem/30331444> Reviewed by Anders Carlsson. ConstraintHolder returns a reference to an object created by operator new. When the returned value is assigned or stored in Vector or other containers we leak memory. Instead, this value should just be returned as a regular object so that the return value optimization can make sure memory is properly (and efficiently) used. * platform/mediastream/MediaConstraints.h: (WebCore::FlattenedConstraint::ConstraintHolder::create): Return by value. Canonical link: https://commits.webkit.org/184789@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@211579 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 09b8bd0 commit 613d76a

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

Source/WebCore/ChangeLog

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
2017-02-02 Brent Fulgham <bfulgham@apple.com>
2+
3+
Correct memory leak in MediaConstraints
4+
https://bugs.webkit.org/show_bug.cgi?id=167744
5+
<rdar://problem/30331444>
6+
7+
Reviewed by Anders Carlsson.
8+
9+
ConstraintHolder returns a reference to an object created by operator new. When the
10+
returned value is assigned or stored in Vector or other containers we leak memory.
11+
Instead, this value should just be returned as a regular object so that the return
12+
value optimization can make sure memory is properly (and efficiently) used.
13+
14+
* platform/mediastream/MediaConstraints.h:
15+
(WebCore::FlattenedConstraint::ConstraintHolder::create): Return by value.
16+
117
2017-02-02 Andreas Kling <akling@apple.com>
218

319
[Mac] In-process memory pressure monitor for WebContent processes AKA websam

Source/WebCore/platform/mediastream/MediaConstraints.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ class FlattenedConstraint {
713713
private:
714714
class ConstraintHolder {
715715
public:
716-
static ConstraintHolder& create(const MediaConstraint& value) { return *new ConstraintHolder(value); }
716+
static ConstraintHolder create(const MediaConstraint& value) { return ConstraintHolder(value); }
717717

718718
~ConstraintHolder()
719719
{

0 commit comments

Comments
 (0)