From d70e8c144505fd57d4a019e5a88468b9960c493e Mon Sep 17 00:00:00 2001 From: daniel Date: Thu, 31 Jan 2013 10:46:02 +0900 Subject: Return null from open if something failed. --- libvxi11client/perlbits/perlglue.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libvxi11client/perlbits/perlglue.c b/libvxi11client/perlbits/perlglue.c index dafc707..5c9f4c2 100644 --- a/libvxi11client/perlbits/perlglue.c +++ b/libvxi11client/perlbits/perlglue.c @@ -49,11 +49,17 @@ static void interruptcallback(gchar* handle) { */ VXI11Context* glue_open(char* address, char* device) { - VXI11Context* context = malloc(sizeof(VXI11Context)); + VXI11Context* context = g_malloc(sizeof(VXI11Context)); if (context == NULL ) return NULL ; - int err = vxi11_open(context, address, device); + int ret = vxi11_open(context, address, device); + // if the connection fails dump the context and return null + // so perl can see what happened + if (ret < 1) { + g_free(context); + context = NULL; + } return context; } -- cgit