Bug 964561 - Part 10: Fix a possible leak in BindAdoptedBlobByName()/BindAdoptedBlobByIndex(); r=mak
authorJan Varga <jan.varga@gmail.com>
Tue, 25 Oct 2016 21:18:37 +0200
changeset 319392 e1c649956724f62b645d146b758f415b8b27df90
parent 319391 1e2c6afa8a5e01c94c0f68387a834e769bc57c0e
child 319393 7dd47b2b08073411f6096e54d577bb1069d87ace
push id83152
push userjvarga@mozilla.com
push dateTue, 25 Oct 2016 19:20:05 +0000
treeherdermozilla-inbound@d0751b15d579 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs964561
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 964561 - Part 10: Fix a possible leak in BindAdoptedBlobByName()/BindAdoptedBlobByIndex(); r=mak
storage/mozStorageBindingParams.cpp
--- a/storage/mozStorageBindingParams.cpp
+++ b/storage/mozStorageBindingParams.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <limits.h>
 
+#include "mozilla/UniquePtrExtensions.h"
 #include "nsString.h"
 
 #include "mozStorageError.h"
 #include "mozStoragePrivateHelpers.h"
 #include "mozStorageBindingParams.h"
 #include "mozStorageBindingParamsArray.h"
 #include "Variant.h"
 
@@ -362,21 +363,19 @@ BindingParams::BindUTF8StringAsBlobByNam
 }
 
 
 NS_IMETHODIMP
 BindingParams::BindAdoptedBlobByName(const nsACString &aName,
                                      uint8_t *aValue,
                                      uint32_t aValueSize)
 {
+  UniqueFreePtr<uint8_t> uniqueValue(aValue);
   NS_ENSURE_ARG_MAX(aValueSize, INT_MAX);
-  std::pair<uint8_t *, int> data(
-    aValue,
-    int(aValueSize)
-  );
+  std::pair<uint8_t *, int> data(uniqueValue.release(), int(aValueSize));
   nsCOMPtr<nsIVariant> value(new AdoptedBlobVariant(data));
 
   return BindByName(aName, value);
 }
 
 NS_IMETHODIMP
 BindingParams::BindByIndex(uint32_t aIndex,
                            nsIVariant *aValue)
@@ -509,20 +508,18 @@ BindingParams::BindUTF8StringAsBlobByInd
   return DoBindStringAsBlobByIndex(this, aIndex, aValue);
 }
 
 NS_IMETHODIMP
 BindingParams::BindAdoptedBlobByIndex(uint32_t aIndex,
                                       uint8_t *aValue,
                                       uint32_t aValueSize)
 {
+  UniqueFreePtr<uint8_t> uniqueValue(aValue);
   NS_ENSURE_ARG_MAX(aValueSize, INT_MAX);
-  std::pair<uint8_t *, int> data(
-    static_cast<uint8_t *>(aValue),
-    int(aValueSize)
-  );
+  std::pair<uint8_t *, int> data(uniqueValue.release(), int(aValueSize));
   nsCOMPtr<nsIVariant> value(new AdoptedBlobVariant(data));
 
   return BindByIndex(aIndex, value);
 }
 
 } // namespace storage
 } // namespace mozilla