Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(390)

Side by Side Diff: dbus/message.cc

Issue 7573001: Fix subtle memory issues detected by valgrind. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "dbus/message.h" 5 #include "dbus/message.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/format_macros.h" 8 #include "base/format_macros.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 } 254 }
255 255
256 MessageWriter::~MessageWriter() { 256 MessageWriter::~MessageWriter() {
257 } 257 }
258 258
259 void MessageWriter::AppendByte(uint8 value) { 259 void MessageWriter::AppendByte(uint8 value) {
260 AppendBasic(DBUS_TYPE_BYTE, &value); 260 AppendBasic(DBUS_TYPE_BYTE, &value);
261 } 261 }
262 262
263 void MessageWriter::AppendBool(bool value) { 263 void MessageWriter::AppendBool(bool value) {
264 AppendBasic(DBUS_TYPE_BOOLEAN, &value); 264 // The size of dbus_bool_t and the size of bool are different. The
265 // former is always 4 per dbus-types.h, whereas the latter is usually 1.
266 // dbus_message_iter_append_basic() used in AppendBasic() expects four
267 // bytes for DBUS_TYPE_BOOLEAN, so we must pass a dbus_bool_t, instead
268 // of a bool, to AppendBasic().
269 dbus_bool_t dbus_value = value;
270 AppendBasic(DBUS_TYPE_BOOLEAN, &dbus_value);
265 } 271 }
266 272
267 void MessageWriter::AppendInt16(int16 value) { 273 void MessageWriter::AppendInt16(int16 value) {
268 AppendBasic(DBUS_TYPE_INT16, &value); 274 AppendBasic(DBUS_TYPE_INT16, &value);
269 } 275 }
270 276
271 void MessageWriter::AppendUint16(uint16 value) { 277 void MessageWriter::AppendUint16(uint16 value) {
272 AppendBasic(DBUS_TYPE_UINT16, &value); 278 AppendBasic(DBUS_TYPE_UINT16, &value);
273 } 279 }
274 280
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 static_cast<int>(length)); 389 static_cast<int>(length));
384 CHECK(success) << "Unable to allocate memory"; 390 CHECK(success) << "Unable to allocate memory";
385 CloseContainer(&array_writer); 391 CloseContainer(&array_writer);
386 } 392 }
387 393
388 void MessageWriter::AppendVariantOfByte(uint8 value) { 394 void MessageWriter::AppendVariantOfByte(uint8 value) {
389 AppendVariantOfBasic(DBUS_TYPE_BYTE, &value); 395 AppendVariantOfBasic(DBUS_TYPE_BYTE, &value);
390 } 396 }
391 397
392 void MessageWriter::AppendVariantOfBool(bool value) { 398 void MessageWriter::AppendVariantOfBool(bool value) {
393 AppendVariantOfBasic(DBUS_TYPE_BOOLEAN, &value); 399 // See the comment at MessageWriter::AppendBool().
400 dbus_bool_t dbus_value = value;
401 AppendVariantOfBasic(DBUS_TYPE_BOOLEAN, &dbus_value);
394 } 402 }
395 403
396 void MessageWriter::AppendVariantOfInt16(int16 value) { 404 void MessageWriter::AppendVariantOfInt16(int16 value) {
397 AppendVariantOfBasic(DBUS_TYPE_INT16, &value); 405 AppendVariantOfBasic(DBUS_TYPE_INT16, &value);
398 } 406 }
399 407
400 void MessageWriter::AppendVariantOfUint16(uint16 value) { 408 void MessageWriter::AppendVariantOfUint16(uint16 value) {
401 AppendVariantOfBasic(DBUS_TYPE_UINT16, &value); 409 AppendVariantOfBasic(DBUS_TYPE_UINT16, &value);
402 } 410 }
403 411
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 bool MessageReader::HasMoreData() { 474 bool MessageReader::HasMoreData() {
467 const int dbus_type = dbus_message_iter_get_arg_type(&raw_message_iter_); 475 const int dbus_type = dbus_message_iter_get_arg_type(&raw_message_iter_);
468 return dbus_type != DBUS_TYPE_INVALID; 476 return dbus_type != DBUS_TYPE_INVALID;
469 } 477 }
470 478
471 bool MessageReader::PopByte(uint8* value) { 479 bool MessageReader::PopByte(uint8* value) {
472 return PopBasic(DBUS_TYPE_BYTE, value); 480 return PopBasic(DBUS_TYPE_BYTE, value);
473 } 481 }
474 482
475 bool MessageReader::PopBool(bool* value) { 483 bool MessageReader::PopBool(bool* value) {
476 return PopBasic(DBUS_TYPE_BOOLEAN, value); 484 // Like MessageWriter::AppendBool(), we should copy |value| to
485 // dbus_bool_t, as dbus_message_iter_get_basic() used in PopBasic()
486 // expects four bytes for DBUS_TYPE_BOOLEAN.
487 dbus_bool_t dbus_value = FALSE;
488 const bool success = PopBasic(DBUS_TYPE_BOOLEAN, &dbus_value);
489 *value = static_cast<bool>(dbus_value);
490 return success;
477 } 491 }
478 492
479 bool MessageReader::PopInt16(int16* value) { 493 bool MessageReader::PopInt16(int16* value) {
480 return PopBasic(DBUS_TYPE_INT16, value); 494 return PopBasic(DBUS_TYPE_INT16, value);
481 } 495 }
482 496
483 bool MessageReader::PopUint16(uint16* value) { 497 bool MessageReader::PopUint16(uint16* value) {
484 return PopBasic(DBUS_TYPE_UINT16, value); 498 return PopBasic(DBUS_TYPE_UINT16, value);
485 } 499 }
486 500
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 object_paths->push_back(object_path); 576 object_paths->push_back(object_path);
563 } 577 }
564 return true; 578 return true;
565 } 579 }
566 580
567 bool MessageReader::PopVariantOfByte(uint8* value) { 581 bool MessageReader::PopVariantOfByte(uint8* value) {
568 return PopVariantOfBasic(DBUS_TYPE_BYTE, value); 582 return PopVariantOfBasic(DBUS_TYPE_BYTE, value);
569 } 583 }
570 584
571 bool MessageReader::PopVariantOfBool(bool* value) { 585 bool MessageReader::PopVariantOfBool(bool* value) {
572 return PopVariantOfBasic(DBUS_TYPE_BOOLEAN, value); 586 // See the comment at MessageReader::PopBool().
587 dbus_bool_t dbus_value = FALSE;
588 const bool success = PopVariantOfBasic(DBUS_TYPE_BOOLEAN, &dbus_value);
589 *value = static_cast<bool>(dbus_value);
590 return success;
573 } 591 }
574 592
575 bool MessageReader::PopVariantOfInt16(int16* value) { 593 bool MessageReader::PopVariantOfInt16(int16* value) {
576 return PopVariantOfBasic(DBUS_TYPE_INT16, value); 594 return PopVariantOfBasic(DBUS_TYPE_INT16, value);
577 } 595 }
578 596
579 bool MessageReader::PopVariantOfUint16(uint16* value) { 597 bool MessageReader::PopVariantOfUint16(uint16* value) {
580 return PopVariantOfBasic(DBUS_TYPE_UINT16, value); 598 return PopVariantOfBasic(DBUS_TYPE_UINT16, value);
581 } 599 }
582 600
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 } 673 }
656 674
657 bool MessageReader::PopVariantOfBasic(int dbus_type, void* value) { 675 bool MessageReader::PopVariantOfBasic(int dbus_type, void* value) {
658 dbus::MessageReader variant_reader(message_); 676 dbus::MessageReader variant_reader(message_);
659 if (!PopVariant(&variant_reader)) 677 if (!PopVariant(&variant_reader))
660 return false; 678 return false;
661 return variant_reader.PopBasic(dbus_type, value); 679 return variant_reader.PopBasic(dbus_type, value);
662 } 680 }
663 681
664 } // namespace dbus 682 } // namespace dbus
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698