Commit f89c3a34 authored by pvalenzuela's avatar pvalenzuela Committed by Commit bot

Fix memory leak in Sync FakeServerEntity

SyncEntity protos in fake_server.cc are now populated by passing a
pointer to FakeServerEntity.SerializeAsProto. Previously,
SerializeAsProto returned a newly-created proto that was never deleted.

BUG=NONE

Review URL: https://codereview.chromium.org/600083003

Cr-Commit-Position: refs/heads/master@{#296733}
parent aa536251
...@@ -108,25 +108,21 @@ string BookmarkEntity::GetParentId() const { ...@@ -108,25 +108,21 @@ string BookmarkEntity::GetParentId() const {
return parent_id_; return parent_id_;
} }
sync_pb::SyncEntity* BookmarkEntity::SerializeAsProto() { void BookmarkEntity::SerializeAsProto(sync_pb::SyncEntity* proto) {
sync_pb::SyncEntity* sync_entity = new sync_pb::SyncEntity(); FakeServerEntity::SerializeBaseProtoFields(proto);
FakeServerEntity::SerializeBaseProtoFields(sync_entity);
sync_pb::EntitySpecifics* specifics = sync_entity->mutable_specifics(); sync_pb::EntitySpecifics* specifics = proto->mutable_specifics();
specifics->CopyFrom(specifics_); specifics->CopyFrom(specifics_);
sync_entity->set_originator_cache_guid(originator_cache_guid_); proto->set_originator_cache_guid(originator_cache_guid_);
sync_entity->set_originator_client_item_id(originator_client_item_id_); proto->set_originator_client_item_id(originator_client_item_id_);
sync_entity->set_parent_id_string(parent_id_); proto->set_parent_id_string(parent_id_);
sync_entity->set_ctime(creation_time_); proto->set_ctime(creation_time_);
sync_entity->set_mtime(last_modified_time_); proto->set_mtime(last_modified_time_);
sync_pb::UniquePosition* unique_position = sync_pb::UniquePosition* unique_position = proto->mutable_unique_position();
sync_entity->mutable_unique_position();
unique_position->CopyFrom(unique_position_); unique_position->CopyFrom(unique_position_);
return sync_entity;
} }
bool BookmarkEntity::IsDeleted() const { bool BookmarkEntity::IsDeleted() const {
......
...@@ -50,7 +50,7 @@ class BookmarkEntity : public FakeServerEntity { ...@@ -50,7 +50,7 @@ class BookmarkEntity : public FakeServerEntity {
// FakeServerEntity implementation. // FakeServerEntity implementation.
virtual std::string GetParentId() const OVERRIDE; virtual std::string GetParentId() const OVERRIDE;
virtual sync_pb::SyncEntity* SerializeAsProto() OVERRIDE; virtual void SerializeAsProto(sync_pb::SyncEntity* proto) OVERRIDE;
virtual bool IsDeleted() const OVERRIDE; virtual bool IsDeleted() const OVERRIDE;
virtual bool IsFolder() const OVERRIDE; virtual bool IsFolder() const OVERRIDE;
......
...@@ -288,7 +288,7 @@ bool FakeServer::HandleGetUpdatesRequest( ...@@ -288,7 +288,7 @@ bool FakeServer::HandleGetUpdatesRequest(
FakeServerEntity* entity = it->second; FakeServerEntity* entity = it->second;
if (sieve->ClientWantsItem(entity)) { if (sieve->ClientWantsItem(entity)) {
sync_pb::SyncEntity* response_entity = response->add_entries(); sync_pb::SyncEntity* response_entity = response->add_entries();
response_entity->CopyFrom(*(entity->SerializeAsProto())); entity->SerializeAsProto(response_entity);
max_response_version = std::max(max_response_version, max_response_version = std::max(max_response_version,
response_entity->version()); response_entity->version());
......
...@@ -38,7 +38,7 @@ class FakeServerEntity { ...@@ -38,7 +38,7 @@ class FakeServerEntity {
// Common data items needed by server // Common data items needed by server
virtual std::string GetParentId() const = 0; virtual std::string GetParentId() const = 0;
virtual sync_pb::SyncEntity* SerializeAsProto() = 0; virtual void SerializeAsProto(sync_pb::SyncEntity* proto) = 0;
virtual bool IsDeleted() const = 0; virtual bool IsDeleted() const = 0;
virtual bool IsFolder() const = 0; virtual bool IsFolder() const = 0;
......
...@@ -98,17 +98,14 @@ string PermanentEntity::GetParentId() const { ...@@ -98,17 +98,14 @@ string PermanentEntity::GetParentId() const {
return parent_id_; return parent_id_;
} }
sync_pb::SyncEntity* PermanentEntity::SerializeAsProto() { void PermanentEntity::SerializeAsProto(sync_pb::SyncEntity* proto) {
sync_pb::SyncEntity* sync_entity = new sync_pb::SyncEntity(); FakeServerEntity::SerializeBaseProtoFields(proto);
FakeServerEntity::SerializeBaseProtoFields(sync_entity);
sync_pb::EntitySpecifics* specifics = sync_entity->mutable_specifics(); sync_pb::EntitySpecifics* specifics = proto->mutable_specifics();
specifics->CopyFrom(specifics_); specifics->CopyFrom(specifics_);
sync_entity->set_parent_id_string(parent_id_); proto->set_parent_id_string(parent_id_);
sync_entity->set_server_defined_unique_tag(server_defined_unique_tag_); proto->set_server_defined_unique_tag(server_defined_unique_tag_);
return sync_entity;
} }
bool PermanentEntity::IsDeleted() const { bool PermanentEntity::IsDeleted() const {
......
...@@ -38,7 +38,7 @@ class PermanentEntity : public FakeServerEntity { ...@@ -38,7 +38,7 @@ class PermanentEntity : public FakeServerEntity {
// FakeServerEntity implementation. // FakeServerEntity implementation.
virtual std::string GetParentId() const OVERRIDE; virtual std::string GetParentId() const OVERRIDE;
virtual sync_pb::SyncEntity* SerializeAsProto() OVERRIDE; virtual void SerializeAsProto(sync_pb::SyncEntity* proto) OVERRIDE;
virtual bool IsDeleted() const OVERRIDE; virtual bool IsDeleted() const OVERRIDE;
virtual bool IsFolder() const OVERRIDE; virtual bool IsFolder() const OVERRIDE;
......
...@@ -32,14 +32,11 @@ string TombstoneEntity::GetParentId() const { ...@@ -32,14 +32,11 @@ string TombstoneEntity::GetParentId() const {
return string(); return string();
} }
sync_pb::SyncEntity* TombstoneEntity::SerializeAsProto() { void TombstoneEntity::SerializeAsProto(sync_pb::SyncEntity* proto) {
sync_pb::SyncEntity* sync_entity = new sync_pb::SyncEntity(); FakeServerEntity::SerializeBaseProtoFields(proto);
FakeServerEntity::SerializeBaseProtoFields(sync_entity);
sync_pb::EntitySpecifics* specifics = sync_entity->mutable_specifics(); sync_pb::EntitySpecifics* specifics = proto->mutable_specifics();
AddDefaultFieldValue(FakeServerEntity::GetModelType(), specifics); AddDefaultFieldValue(FakeServerEntity::GetModelType(), specifics);
return sync_entity;
} }
bool TombstoneEntity::IsDeleted() const { bool TombstoneEntity::IsDeleted() const {
......
...@@ -24,7 +24,7 @@ class TombstoneEntity : public FakeServerEntity { ...@@ -24,7 +24,7 @@ class TombstoneEntity : public FakeServerEntity {
// FakeServerEntity implementation. // FakeServerEntity implementation.
virtual std::string GetParentId() const OVERRIDE; virtual std::string GetParentId() const OVERRIDE;
virtual sync_pb::SyncEntity* SerializeAsProto() OVERRIDE; virtual void SerializeAsProto(sync_pb::SyncEntity* proto) OVERRIDE;
virtual bool IsDeleted() const OVERRIDE; virtual bool IsDeleted() const OVERRIDE;
virtual bool IsFolder() const OVERRIDE; virtual bool IsFolder() const OVERRIDE;
......
...@@ -68,19 +68,16 @@ string UniqueClientEntity::GetParentId() const { ...@@ -68,19 +68,16 @@ string UniqueClientEntity::GetParentId() const {
return FakeServerEntity::GetTopLevelId(model_type_); return FakeServerEntity::GetTopLevelId(model_type_);
} }
sync_pb::SyncEntity* UniqueClientEntity::SerializeAsProto() { void UniqueClientEntity::SerializeAsProto(sync_pb::SyncEntity* proto) {
sync_pb::SyncEntity* sync_entity = new sync_pb::SyncEntity(); FakeServerEntity::SerializeBaseProtoFields(proto);
FakeServerEntity::SerializeBaseProtoFields(sync_entity);
sync_pb::EntitySpecifics* specifics = sync_entity->mutable_specifics(); sync_pb::EntitySpecifics* specifics = proto->mutable_specifics();
specifics->CopyFrom(specifics_); specifics->CopyFrom(specifics_);
sync_entity->set_parent_id_string(GetParentId()); proto->set_parent_id_string(GetParentId());
sync_entity->set_client_defined_unique_tag(client_defined_unique_tag_); proto->set_client_defined_unique_tag(client_defined_unique_tag_);
sync_entity->set_ctime(creation_time_); proto->set_ctime(creation_time_);
sync_entity->set_mtime(last_modified_time_); proto->set_mtime(last_modified_time_);
return sync_entity;
} }
bool UniqueClientEntity::IsDeleted() const { bool UniqueClientEntity::IsDeleted() const {
......
...@@ -28,7 +28,7 @@ class UniqueClientEntity : public FakeServerEntity { ...@@ -28,7 +28,7 @@ class UniqueClientEntity : public FakeServerEntity {
// FakeServerEntity implementation. // FakeServerEntity implementation.
virtual std::string GetParentId() const OVERRIDE; virtual std::string GetParentId() const OVERRIDE;
virtual sync_pb::SyncEntity* SerializeAsProto() OVERRIDE; virtual void SerializeAsProto(sync_pb::SyncEntity* proto) OVERRIDE;
virtual bool IsDeleted() const OVERRIDE; virtual bool IsDeleted() const OVERRIDE;
virtual bool IsFolder() const OVERRIDE; virtual bool IsFolder() const OVERRIDE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment