[arrayfire] 121/408: Fix double free issue.

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Sep 21 19:11:34 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch debian/sid
in repository arrayfire.

commit 30cbbc7b0ff3566908413930b641ae9278c9a841
Author: Filipe Maia <filipe.c.maia at gmail.com>
Date:   Wed Jul 8 18:17:37 2015 +0200

    Fix double free issue.
---
 include/af/index.h    | 20 ++++++++++++++++++++
 src/api/cpp/index.cpp | 14 ++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/include/af/index.h b/include/af/index.h
index 2957390..7d0763b 100644
--- a/include/af/index.h
+++ b/include/af/index.h
@@ -104,6 +104,15 @@ class AFAPI index {
     index(const af::array& idx0);
 
     ///
+    /// \brief Copy constructor
+    ///
+    /// \param[in] idx0 is index to copy.
+    ///
+    /// \sa indexing
+    ///
+    index(const index& idx0);
+
+    ///
     /// \brief Returns true if the \ref af::index represents a af::span object
     ///
     /// \returns true if the af::index is an af::span
@@ -116,6 +125,17 @@ class AFAPI index {
     /// \returns the af_index_t represented by this object
     ///
     const af_index_t& get() const;
+
+    ///
+    /// \brief Assigns idx0 to this index
+    ///
+    /// \param[in] idx0 is the index to be assigned to the /ref af::index
+    /// \returns the reference to this
+    /// 
+    ///
+    index & operator=(const index& idx0);
+
+
 };
 
 ///
diff --git a/src/api/cpp/index.cpp b/src/api/cpp/index.cpp
index 2b66dd6..afaa716 100644
--- a/src/api/cpp/index.cpp
+++ b/src/api/cpp/index.cpp
@@ -75,11 +75,25 @@ index::index(const af::array& idx0) {
     impl.isBatch = false;
 }
 
+index::index(const af::index& idx0) {  
+    *this = idx0;
+}
+
 index::~index() {
     if (!impl.isSeq)
         af_release_array(impl.idx.arr);
 }
 
+index & index::operator=(const index& idx0) {
+    impl = idx0.get();
+    if(impl.isSeq == false){
+        // increment reference count to avoid double free
+        // when/if idx0 is destroyed
+        AF_THROW(af_retain_array(&impl.idx.arr, impl.idx.arr));
+    }
+    return *this;
+}
+
 
 static bool operator==(const af_seq& lhs, const af_seq& rhs) {
     return lhs.begin == rhs.begin && lhs.end == rhs.end && lhs.step == rhs.step;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/arrayfire.git



More information about the debian-science-commits mailing list