Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
0977815a
Commit
0977815a
authored
Aug 26, 2015
by
Jisi Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix "memory leaks" in protostream-object files.
Change-Id: I0aca56802d974cb03cb89c1a294f37068b5b9758
parent
01e060f2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
52 deletions
+72
-52
protostream_objectsource.cc
...google/protobuf/util/internal/protostream_objectsource.cc
+30
-22
protostream_objectsource.h
src/google/protobuf/util/internal/protostream_objectsource.h
+3
-1
protostream_objectwriter.cc
...google/protobuf/util/internal/protostream_objectwriter.cc
+36
-28
protostream_objectwriter.h
src/google/protobuf/util/internal/protostream_objectwriter.h
+3
-1
No files found.
src/google/protobuf/util/internal/protostream_objectsource.cc
View file @
0977815a
...
...
@@ -47,6 +47,7 @@
#include <google/protobuf/util/internal/utility.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/map_util.h>
#include <google/protobuf/stubs/once.h>
#include <google/protobuf/stubs/status_macros.h>
...
...
@@ -648,46 +649,53 @@ Status ProtoStreamObjectSource::RenderFieldMask(
}
hash_map
<
string
,
ProtoStreamObjectSource
::
TypeRenderer
>*
ProtoStreamObjectSource
::
CreateRendererMap
()
{
hash_map
<
string
,
ProtoStreamObjectSource
::
TypeRenderer
>*
result
=
new
hash_map
<
string
,
ProtoStreamObjectSource
::
TypeRenderer
>
();
(
*
result
)[
"google.protobuf.Timestamp"
]
=
ProtoStreamObjectSource
::
renderers_
=
NULL
;
GOOGLE_PROTOBUF_DECLARE_ONCE
(
source_renderers_init_
);
void
ProtoStreamObjectSource
::
InitRendererMap
()
{
renderers_
=
new
hash_map
<
string
,
ProtoStreamObjectSource
::
TypeRenderer
>
();
(
*
renderers_
)[
"google.protobuf.Timestamp"
]
=
&
ProtoStreamObjectSource
::
RenderTimestamp
;
(
*
re
sult
)[
"google.protobuf.Duration"
]
=
(
*
re
nderers_
)[
"google.protobuf.Duration"
]
=
&
ProtoStreamObjectSource
::
RenderDuration
;
(
*
re
sult
)[
"google.protobuf.DoubleValue"
]
=
(
*
re
nderers_
)[
"google.protobuf.DoubleValue"
]
=
&
ProtoStreamObjectSource
::
RenderDouble
;
(
*
re
sult
)[
"google.protobuf.FloatValue"
]
=
(
*
re
nderers_
)[
"google.protobuf.FloatValue"
]
=
&
ProtoStreamObjectSource
::
RenderFloat
;
(
*
re
sult
)[
"google.protobuf.Int64Value"
]
=
(
*
re
nderers_
)[
"google.protobuf.Int64Value"
]
=
&
ProtoStreamObjectSource
::
RenderInt64
;
(
*
re
sult
)[
"google.protobuf.UInt64Value"
]
=
(
*
re
nderers_
)[
"google.protobuf.UInt64Value"
]
=
&
ProtoStreamObjectSource
::
RenderUInt64
;
(
*
re
sult
)[
"google.protobuf.Int32Value"
]
=
(
*
re
nderers_
)[
"google.protobuf.Int32Value"
]
=
&
ProtoStreamObjectSource
::
RenderInt32
;
(
*
re
sult
)[
"google.protobuf.UInt32Value"
]
=
(
*
re
nderers_
)[
"google.protobuf.UInt32Value"
]
=
&
ProtoStreamObjectSource
::
RenderUInt32
;
(
*
re
sult
)[
"google.protobuf.BoolValue"
]
=
&
ProtoStreamObjectSource
::
RenderBool
;
(
*
re
sult
)[
"google.protobuf.StringValue"
]
=
(
*
re
nderers_
)[
"google.protobuf.BoolValue"
]
=
&
ProtoStreamObjectSource
::
RenderBool
;
(
*
re
nderers_
)[
"google.protobuf.StringValue"
]
=
&
ProtoStreamObjectSource
::
RenderString
;
(
*
re
sult
)[
"google.protobuf.BytesValue"
]
=
(
*
re
nderers_
)[
"google.protobuf.BytesValue"
]
=
&
ProtoStreamObjectSource
::
RenderBytes
;
(
*
re
sult
)[
"google.protobuf.Any"
]
=
&
ProtoStreamObjectSource
::
RenderAny
;
(
*
re
sult
)[
"google.protobuf.Struct"
]
=
&
ProtoStreamObjectSource
::
RenderStruct
;
(
*
re
sult
)[
"google.protobuf.Value"
]
=
(
*
re
nderers_
)[
"google.protobuf.Any"
]
=
&
ProtoStreamObjectSource
::
RenderAny
;
(
*
re
nderers_
)[
"google.protobuf.Struct"
]
=
&
ProtoStreamObjectSource
::
RenderStruct
;
(
*
re
nderers_
)[
"google.protobuf.Value"
]
=
&
ProtoStreamObjectSource
::
RenderStructValue
;
(
*
re
sult
)[
"google.protobuf.ListValue"
]
=
(
*
re
nderers_
)[
"google.protobuf.ListValue"
]
=
&
ProtoStreamObjectSource
::
RenderStructListValue
;
(
*
re
sult
)[
"google.protobuf.FieldMask"
]
=
(
*
re
nderers_
)[
"google.protobuf.FieldMask"
]
=
&
ProtoStreamObjectSource
::
RenderFieldMask
;
return
result
;
::
google
::
protobuf
::
internal
::
OnShutdown
(
&
DeleteRendererMap
);
}
void
ProtoStreamObjectSource
::
DeleteRendererMap
()
{
delete
ProtoStreamObjectSource
::
renderers_
;
renderers_
=
NULL
;
}
// static
ProtoStreamObjectSource
::
TypeRenderer
*
ProtoStreamObjectSource
::
FindTypeRenderer
(
const
string
&
type_url
)
{
static
hash_map
<
string
,
TypeRenderer
>*
renderers
=
CreateRendererMap
(
);
return
FindOrNull
(
*
renderers
,
type_url
);
::
google
::
protobuf
::
GoogleOnceInit
(
&
source_renderers_init_
,
&
InitRendererMap
);
return
FindOrNull
(
*
renderers
_
,
type_url
);
}
Status
ProtoStreamObjectSource
::
RenderField
(
...
...
src/google/protobuf/util/internal/protostream_objectsource.h
View file @
0977815a
...
...
@@ -202,7 +202,9 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectSource : public ObjectSource {
const
google
::
protobuf
::
Type
&
type
,
StringPiece
name
,
ObjectWriter
*
ow
);
static
hash_map
<
string
,
TypeRenderer
>*
CreateRendererMap
();
static
hash_map
<
string
,
TypeRenderer
>*
renderers_
;
static
void
InitRendererMap
();
static
void
DeleteRendererMap
();
static
TypeRenderer
*
FindTypeRenderer
(
const
string
&
type_url
);
// Renders a field value to the ObjectWriter.
...
...
src/google/protobuf/util/internal/protostream_objectwriter.cc
View file @
0977815a
...
...
@@ -39,6 +39,7 @@
#include <google/protobuf/util/internal/object_location_tracker.h>
#include <google/protobuf/util/internal/constants.h>
#include <google/protobuf/util/internal/utility.h>
#include <google/protobuf/stubs/once.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/map_util.h>
#include <google/protobuf/stubs/statusor.h>
...
...
@@ -1365,60 +1366,67 @@ void ProtoStreamObjectWriter::RenderSimpleDataPiece(
// Map of functions that are responsible for rendering well known type
// represented by the key.
hash_map
<
string
,
ProtoStreamObjectWriter
::
TypeRenderer
>*
ProtoStreamObjectWriter
::
CreateRendererMap
()
{
google
::
protobuf
::
scoped_ptr
<
hash_map
<
string
,
ProtoStreamObjectWriter
::
TypeRenderer
>
>
result
(
new
hash_map
<
string
,
ProtoStreamObjectWriter
::
TypeRenderer
>
());
(
*
result
)[
"type.googleapis.com/google.protobuf.Timestamp"
]
=
ProtoStreamObjectWriter
::
renderers_
=
NULL
;
GOOGLE_PROTOBUF_DECLARE_ONCE
(
writer_renderers_init_
);
void
ProtoStreamObjectWriter
::
InitRendererMap
()
{
renderers_
=
new
hash_map
<
string
,
ProtoStreamObjectWriter
::
TypeRenderer
>
();
(
*
renderers_
)[
"type.googleapis.com/google.protobuf.Timestamp"
]
=
&
ProtoStreamObjectWriter
::
RenderTimestamp
;
(
*
re
sult
)[
"type.googleapis.com/google.protobuf.Duration"
]
=
(
*
re
nderers_
)[
"type.googleapis.com/google.protobuf.Duration"
]
=
&
ProtoStreamObjectWriter
::
RenderDuration
;
(
*
re
sult
)[
"type.googleapis.com/google.protobuf.FieldMask"
]
=
(
*
re
nderers_
)[
"type.googleapis.com/google.protobuf.FieldMask"
]
=
&
ProtoStreamObjectWriter
::
RenderFieldMask
;
(
*
re
sult
)[
"type.googleapis.com/google.protobuf.Double"
]
=
(
*
re
nderers_
)[
"type.googleapis.com/google.protobuf.Double"
]
=
&
ProtoStreamObjectWriter
::
RenderWrapperType
;
(
*
re
sult
)[
"type.googleapis.com/google.protobuf.Float"
]
=
(
*
re
nderers_
)[
"type.googleapis.com/google.protobuf.Float"
]
=
&
ProtoStreamObjectWriter
::
RenderWrapperType
;
(
*
re
sult
)[
"type.googleapis.com/google.protobuf.Int64"
]
=
(
*
re
nderers_
)[
"type.googleapis.com/google.protobuf.Int64"
]
=
&
ProtoStreamObjectWriter
::
RenderWrapperType
;
(
*
re
sult
)[
"type.googleapis.com/google.protobuf.UInt64"
]
=
(
*
re
nderers_
)[
"type.googleapis.com/google.protobuf.UInt64"
]
=
&
ProtoStreamObjectWriter
::
RenderWrapperType
;
(
*
re
sult
)[
"type.googleapis.com/google.protobuf.Int32"
]
=
(
*
re
nderers_
)[
"type.googleapis.com/google.protobuf.Int32"
]
=
&
ProtoStreamObjectWriter
::
RenderWrapperType
;
(
*
re
sult
)[
"type.googleapis.com/google.protobuf.UInt32"
]
=
(
*
re
nderers_
)[
"type.googleapis.com/google.protobuf.UInt32"
]
=
&
ProtoStreamObjectWriter
::
RenderWrapperType
;
(
*
re
sult
)[
"type.googleapis.com/google.protobuf.Bool"
]
=
(
*
re
nderers_
)[
"type.googleapis.com/google.protobuf.Bool"
]
=
&
ProtoStreamObjectWriter
::
RenderWrapperType
;
(
*
re
sult
)[
"type.googleapis.com/google.protobuf.String"
]
=
(
*
re
nderers_
)[
"type.googleapis.com/google.protobuf.String"
]
=
&
ProtoStreamObjectWriter
::
RenderWrapperType
;
(
*
re
sult
)[
"type.googleapis.com/google.protobuf.Bytes"
]
=
(
*
re
nderers_
)[
"type.googleapis.com/google.protobuf.Bytes"
]
=
&
ProtoStreamObjectWriter
::
RenderWrapperType
;
(
*
re
sult
)[
"type.googleapis.com/google.protobuf.DoubleValue"
]
=
(
*
re
nderers_
)[
"type.googleapis.com/google.protobuf.DoubleValue"
]
=
&
ProtoStreamObjectWriter
::
RenderWrapperType
;
(
*
re
sult
)[
"type.googleapis.com/google.protobuf.FloatValue"
]
=
(
*
re
nderers_
)[
"type.googleapis.com/google.protobuf.FloatValue"
]
=
&
ProtoStreamObjectWriter
::
RenderWrapperType
;
(
*
re
sult
)[
"type.googleapis.com/google.protobuf.Int64Value"
]
=
(
*
re
nderers_
)[
"type.googleapis.com/google.protobuf.Int64Value"
]
=
&
ProtoStreamObjectWriter
::
RenderWrapperType
;
(
*
re
sult
)[
"type.googleapis.com/google.protobuf.UInt64Value"
]
=
(
*
re
nderers_
)[
"type.googleapis.com/google.protobuf.UInt64Value"
]
=
&
ProtoStreamObjectWriter
::
RenderWrapperType
;
(
*
re
sult
)[
"type.googleapis.com/google.protobuf.Int32Value"
]
=
(
*
re
nderers_
)[
"type.googleapis.com/google.protobuf.Int32Value"
]
=
&
ProtoStreamObjectWriter
::
RenderWrapperType
;
(
*
re
sult
)[
"type.googleapis.com/google.protobuf.UInt32Value"
]
=
(
*
re
nderers_
)[
"type.googleapis.com/google.protobuf.UInt32Value"
]
=
&
ProtoStreamObjectWriter
::
RenderWrapperType
;
(
*
re
sult
)[
"type.googleapis.com/google.protobuf.BoolValue"
]
=
(
*
re
nderers_
)[
"type.googleapis.com/google.protobuf.BoolValue"
]
=
&
ProtoStreamObjectWriter
::
RenderWrapperType
;
(
*
re
sult
)[
"type.googleapis.com/google.protobuf.StringValue"
]
=
(
*
re
nderers_
)[
"type.googleapis.com/google.protobuf.StringValue"
]
=
&
ProtoStreamObjectWriter
::
RenderWrapperType
;
(
*
re
sult
)[
"type.googleapis.com/google.protobuf.BytesValue"
]
=
(
*
re
nderers_
)[
"type.googleapis.com/google.protobuf.BytesValue"
]
=
&
ProtoStreamObjectWriter
::
RenderWrapperType
;
(
*
re
sult
)[
"type.googleapis.com/google.protobuf.Value"
]
=
(
*
re
nderers_
)[
"type.googleapis.com/google.protobuf.Value"
]
=
&
ProtoStreamObjectWriter
::
RenderStructValue
;
return
result
.
release
();
::
google
::
protobuf
::
internal
::
OnShutdown
(
&
DeleteRendererMap
);
}
void
ProtoStreamObjectWriter
::
DeleteRendererMap
()
{
delete
ProtoStreamObjectWriter
::
renderers_
;
renderers_
=
NULL
;
}
ProtoStreamObjectWriter
::
TypeRenderer
*
ProtoStreamObjectWriter
::
FindTypeRenderer
(
const
string
&
type_url
)
{
static
hash_map
<
string
,
TypeRenderer
>*
renderers
=
CreateRendererMap
(
);
return
FindOrNull
(
*
renderers
,
type_url
);
::
google
::
protobuf
::
GoogleOnceInit
(
&
writer_renderers_init_
,
&
InitRendererMap
);
return
FindOrNull
(
*
renderers
_
,
type_url
);
}
ProtoStreamObjectWriter
::
ProtoElement
::
ElementType
...
...
src/google/protobuf/util/internal/protostream_objectwriter.h
View file @
0977815a
...
...
@@ -407,7 +407,9 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public StructuredObjectWriter
// Helper functions to create the map and find functions responsible for
// rendering well known types, keyed by type URL.
static
hash_map
<
string
,
TypeRenderer
>*
CreateRendererMap
();
static
hash_map
<
string
,
TypeRenderer
>*
renderers_
;
static
void
InitRendererMap
();
static
void
DeleteRendererMap
();
static
TypeRenderer
*
FindTypeRenderer
(
const
string
&
type_url
);
// Returns the ProtoElement::ElementType for the given Type.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment