From 7798638dd9d4dfb4ee2fe57b4eab5cf443a2b933 Mon Sep 17 00:00:00 2001 From: Braiden Vasco Date: Sat, 12 Sep 2015 00:37:14 +0000 Subject: [PATCH] Handle error for tox_new() --- ext/tox/tox.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ext/tox/tox.c b/ext/tox/tox.c index d7111d9..c276731 100644 --- a/ext/tox/tox.c +++ b/ext/tox/tox.c @@ -58,6 +58,8 @@ VALUE cTox_initialize(const VALUE self, const VALUE options) cTox_ *tox; cTox_cOptions_ *tox_options; + TOX_ERR_NEW error; + // check if `options` is instance of `Tox::Options` if (Qfalse == rb_funcall(options, rb_intern("is_a?"), 1, cTox_cOptions)) rb_raise(rb_eTypeError, "argument 1 should be Tox::Options"); @@ -65,7 +67,10 @@ VALUE cTox_initialize(const VALUE self, const VALUE options) Data_Get_Struct(self, cTox_, tox); Data_Get_Struct(options, cTox_cOptions_, tox_options); - tox->tox = tox_new(tox_options, NULL); + tox->tox = tox_new(tox_options, &error); + + if (error != TOX_ERR_NEW_OK) + rb_raise(rb_eRuntimeError, "tox_new() failed"); return self; }