Skip to content

Commit

Permalink
fix issue with double frees when assigning an array
Browse files Browse the repository at this point in the history
  • Loading branch information
Aljar committed Jun 10, 2016
1 parent f37b04f commit babf644
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ class Data
* @return Modifier* nullptr in case it isn't found
*/
Modifier *modifier(const char *name, size_t size) const;

/**
* contains a specific value
* @param const Value* a pointer to the value
* @return boolean
*/
bool contains(const Value *value) const;
};

/**
Expand Down
19 changes: 19 additions & 0 deletions src/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,25 @@ Modifier *Data::modifier(const char* name, size_t size) const
return iter->second;
}

/**
* contains a specific value
* @param const Value* a pointer to the value
* @return boolean
*/
bool Data::contains(const Value *value) const
{
// iterate over all values
for (const auto &variable :_variables)
{
// if pointers are identical it is in the data object
if (variable.second == value) return true;
}

// the value was not found
return false;
}


/**
* End namespace
*/
Expand Down
3 changes: 3 additions & 0 deletions src/handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ class Handler
if (v.get() == value) return false;
}

// if it is already hold by the data object we also do not have to manage it
if (_data->contains(value)) return false;

// If they are not we start managing it
_managed_local_values.emplace_back(value);

Expand Down

0 comments on commit babf644

Please sign in to comment.