Permalink
Browse files

YAwn: Fix memory leaks

  • Loading branch information...
sanssecours committed Oct 7, 2018
1 parent 735096d commit 54f6e380cae0fc63c0efacc97216efbc878b8b9c
Showing with 5 additions and 30 deletions.
  1. +1 −1 scripts/docker/alpine/3.8/Dockerfile
  2. +1 −1 src/plugins/yawn/README.md
  3. +3 −28 src/plugins/yawn/convert.cpp
@@ -22,7 +22,7 @@ RUN mkdir -p ${GTEST_ROOT} \
# YAEP
RUN cd /tmp \
&& git clone https://github.com/sanssecours/yaep.git \
&& git clone --depth 1 https://github.com/sanssecours/yaep.git \
&& cd yaep \
&& env CXXFLAGS='-fPIC' ./configure \
&& make -C src install
@@ -5,7 +5,7 @@
- infos/provides = storage/yaml
- infos/recommends =
- infos/placements = getstorage
- infos/status = maintained unittest preview memleak experimental unfinished nodoc concept discouraged
- infos/status = maintained unittest preview experimental unfinished nodoc concept discouraged
- infos/metadata =
- infos/description = This storage plugin use a Early parser to read YAML files
@@ -90,20 +90,6 @@ void syntaxError (int errorToken, void * errorTokenData, int ignoredToken, void
recoveredTokenData);
}
/**
* This function allocates a memory region of the given size.
*
* @param size This variable specifies the amount of data this method should
* allocate.
*
* @return A pointer to a memory region of the specified size
*/
inline void * alloc (int size)
{
return elektraMalloc (size);
}
/**
* @brief This function parses the YAML grammar contained in `yaml.bnf`.
*
@@ -200,13 +186,7 @@ namespace yawn
*/
int addToKeySet (CppKeySet & keySet, CppKey & parent, string const & filename)
{
#ifdef ENABLE_ASAN
__lsan_disable ();
#endif
yaep parser;
#ifdef ENABLE_ASAN
__lsan_enable ();
#endif
auto grammar = parseGrammar (parser, parent);
if (grammar.size () <= 0) return -1;
@@ -223,21 +203,16 @@ int addToKeySet (CppKeySet & keySet, CppKey & parent, string const & filename)
int ambiguousOutput;
struct yaep_tree_node * root = nullptr;
#ifdef ENABLE_ASAN
__lsan_disable ();
#endif
// TODO: Free parse tree after YAEP provides a function to do that
parser.parse (nextToken, syntaxError, alloc, elektraFree, &root, &ambiguousOutput);
#ifdef ENABLE_ASAN
__lsan_enable ();
#endif
parser.parse (nextToken, syntaxError, nullptr, nullptr, &root, &ambiguousOutput);
if (handleErrors (ambiguousOutput, errorListener, filename, grammar, parent) < 0) return -1;
Listener listener{ parent };
walk (listener, root);
keySet.append (listener.getKeySet ());
yaep::free_tree (root, nullptr, nullptr);
return listener.getKeySet ().size () > 0;
}

0 comments on commit 54f6e38

Please sign in to comment.