Skip to content

Fix double free issue. Closes #894#895

Merged
umar456 merged 3 commits into
arrayfire:develfrom
FilipeMaia:devel
Jul 10, 2015
Merged

Fix double free issue. Closes #894#895
umar456 merged 3 commits into
arrayfire:develfrom
FilipeMaia:devel

Conversation

@FilipeMaia
Copy link
Copy Markdown
Contributor

Closes #894

@pavanky
Copy link
Copy Markdown
Member

pavanky commented Jul 8, 2015

@FilipeMaia Can you remove the "Closes #894" from the commit message and put it as a description in the PR?

@pavanky pavanky added this to the 3.1.0 milestone Jul 8, 2015
@FilipeMaia
Copy link
Copy Markdown
Contributor Author

Can i just force push the amended commit message or do i need a new pull request?

@umar456
Copy link
Copy Markdown
Member

umar456 commented Jul 8, 2015

Hi @FilipeMaia, Thanks for finding this issue.

The problem is that af::index is only used to simplify the operator() overloads. It allows us to support any arbitrary combination of int, af::seq or af::array objects to index into an array. It is never meant to be created. I think a better solution would be to make the af::index default constructor private so that it cannot be created without referencing one of the other constructors.

@pavanky
Copy link
Copy Markdown
Member

pavanky commented Jul 8, 2015

Force push is fine.

@FilipeMaia
Copy link
Copy Markdown
Contributor Author

@umar456, I think that having things in the public API which are not supposed to be manipulated by the users, such as af::index and af::array::array_proxy is a sure way to lead to problems in the future.

Just making the default constructor private is not enough. You also need to avoid the creation of af::index::operator=, and there might be other things we haven't thought about.

@pavanky
Copy link
Copy Markdown
Member

pavanky commented Jul 8, 2015

@umar456 For better or worse it is out in the public. We can't change the API now.

@pavanky
Copy link
Copy Markdown
Member

pavanky commented Jul 8, 2015

@FilipeMaia Can you make the code from the failure case as a test ? You can make it a new test in test/index.cpp.

@FilipeMaia
Copy link
Copy Markdown
Contributor Author

I'm not sure if I succeeded making a test. I'm don't know how to test them...

@pavanky
Copy link
Copy Markdown
Member

pavanky commented Jul 8, 2015

That should be enough 👍 Any code snippet that was failing makes a valid test.

@umar456
Copy link
Copy Markdown
Member

umar456 commented Jul 8, 2015

@FilipeMaia Yeah, I forgot about the rule of 3/5. Could you add operator=(index&&) and index(index&&) for the index class with c++11 guards (see:https://github.com/arrayfire/arrayfire/blob/devel/include/af/array.h#L51). These functions will not need to increment the reference count for the array object.

I still think we should make the default constructor private. The index class was not designed to be used this way. @pavanky This change will not break ABI but might cause issues when recompiling for those who used af::index incorrectly.

@FilipeMaia
Copy link
Copy Markdown
Contributor Author

@umar456 such a change would break the ABI because the copy constructor, which is currently public, would become private.

@umar456
Copy link
Copy Markdown
Member

umar456 commented Jul 8, 2015

ABI would not break because the Linker will still create the symbol. The API on the other hand will be different. This will cause issues during recompilation of code which makes use of the af::index default constructor. I would like to make this change but I understand it can cause issues with some users.

@FilipeMaia
Copy link
Copy Markdown
Contributor Author

Ok, I didn't realise the private/public part would not impact the symbol.

@umar456
Copy link
Copy Markdown
Member

umar456 commented Jul 9, 2015

ok to test

@umar456
Copy link
Copy Markdown
Member

umar456 commented Jul 9, 2015

build arrayfire ci

umar456 added a commit that referenced this pull request Jul 10, 2015
Apply Rule of 3/5 on the af::index class.
@umar456 umar456 merged commit 4cc3a9b into arrayfire:devel Jul 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants