added initial code to manage memory allocation error - gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/agg-plot/agg-parse-trans.cpp
diff options
context:
space:
mode:
authorfrancesco-ST <francesco.abbate@st.com>2010年09月01日 16:01:32 +0200
committerfrancesco-ST <francesco.abbate@st.com>2010年09月01日 16:01:32 +0200
commit4806d8bdb82b3c6a221caa3d73d7541c5721a530 (patch)
treefa6a69a6738f5265582a38cd2f157bc07ddf057c /agg-plot/agg-parse-trans.cpp
parent31ed0541a835746f4788d76286f1facea2fcf5aa (diff)
downloadgsl-shell-4806d8bdb82b3c6a221caa3d73d7541c5721a530.tar.gz
added initial code to manage memory allocation error
The code should be tested and improved, this is a first implementation.
Diffstat (limited to 'agg-plot/agg-parse-trans.cpp')
-rw-r--r--agg-plot/agg-parse-trans.cpp 27
1 files changed, 24 insertions, 3 deletions
diff --git a/agg-plot/agg-parse-trans.cpp b/agg-plot/agg-parse-trans.cpp
index 368405fd..14cccb10 100644
--- a/agg-plot/agg-parse-trans.cpp
+++ b/agg-plot/agg-parse-trans.cpp
@@ -231,6 +231,7 @@ parse_spec (lua_State *L, int specindex, typename context::base_type *obj)
lua_rawgeti (L, specindex, 1);
if (! lua_isstring (L, -1))
{
+ lua_management::dispose(obj);
luaL_error (L, "the tag of the transformation is invalid");
return NULL;
}
@@ -241,8 +242,21 @@ parse_spec (lua_State *L, int specindex, typename context::base_type *obj)
typename builder_type::func_type *f = builder_type::lookup(tag);
if (f)
- return f (L, specindex, obj);
+ {
+ try
+ {
+ typename context::base_type *retval = f (L, specindex, obj);
+ return retval;
+ }
+ catch (std::bad_alloc&)
+ {
+ lua_management::dispose(obj);
+ luaL_error (L, "out of memory");
+ return NULL;
+ }
+ }
+ lua_management::dispose(obj);
luaL_error (L, "invalid trasformation tag");
return NULL;
}
@@ -256,6 +270,7 @@ parse_spec_pipeline (lua_State *L, int index, typename context::base_type *obj)
nb = lua_objlen (L, index);
else
{
+ lua_management::dispose(obj);
luaL_error (L, "post transform argument should be a table");
return NULL;
}
@@ -283,7 +298,7 @@ parse_graph_args (lua_State *L)
if (narg > 5)
{
- luaL_error (L, "too much arguments if add or addline plot method");
+ luaL_error (L, "too much arguments in add or addline plot method");
return NULL;
}
@@ -299,7 +314,13 @@ parse_graph_args (lua_State *L)
lua_pop (L, 1);
}
- w = new window_scalable(s);
+ w = new(std::nothrow) window_scalable(s);
+ if (w == 0)
+ {
+ lua_management::dispose(s);
+ luaL_error (L, "out of memory");
+ return NULL;
+ }
}
else if (gs_is_userdata (L, 2, GS_DRAW_DRAWABLE))
{
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月13日 18:25:45 +0000

AltStyle によって変換されたページ (->オリジナル) /