diff --git a/pyopencl/cffi_cl.py b/pyopencl/cffi_cl.py
index 72bd908a3a613aae45363ebfed2d7217795d4b52..5a141a06a0064dbf9e0ad4e90dc296475dfd8484 100644
--- a/pyopencl/cffi_cl.py
+++ b/pyopencl/cffi_cl.py
@@ -232,7 +232,9 @@ def _parse_context_properties(properties):
             # TODO: without ctypes?
             import ctypes
             val = (ctypes.cast(value, ctypes.c_void_p)).value
-            props.append(0 if val is None else val)
+            if val is None:
+                raise LogicError("Context", status_code.INVALID_VALUE, "You most likely have not initialized OpenGL properly.")
+            props.append(val)
         else:
             raise RuntimeError("Context", status_code.INVALID_VALUE, "invalid context property")
     props.append(0)
@@ -412,7 +414,8 @@ def _generic_info_to_python(info):
             ret = list(value)
     else:
         ret = value[0]
-    _lib._free(info.value)
+    if info.dontfree == 0:
+        _lib._free(info.value)
     return ret
 
 class Kernel(_Common):
diff --git a/src/c_wrapper/wrap_cl.cpp b/src/c_wrapper/wrap_cl.cpp
index cc51ff29dbb89bb0625498952500bca2df2528e6..88aa807625c5f200f2c869ae47226ae69a8ddc61 100644
--- a/src/c_wrapper/wrap_cl.cpp
+++ b/src/c_wrapper/wrap_cl.cpp
@@ -76,6 +76,7 @@
     PYOPENCL_CALL_GUARDED(clGet##WHAT##Info,				\
 			  (FIRST_ARG, SECOND_ARG, sizeof(param_value), &param_value, 0)); \
     generic_info info;							\
+    info.dontfree = 0;							\
     info.opaque_class = CLASS_##TYPEU;					\
       info.type = "void *";						\
       if (param_value)							\
@@ -93,6 +94,7 @@
       ar[i] = new pyopencl::CLS(VEC[i]);				\
     }									\
     generic_info info;							\
+    info.dontfree = 0;							\
     info.opaque_class = CLASS_##CLSU;					\
     info.type = _copy_str(std::string("void*[") + tostring(VEC.size()) + "]"); \
     info.value = (void**)ar;						\
@@ -111,6 +113,7 @@
 			  (FIRST_ARG, SECOND_ARG, param_value_size,	\
 			   param_value, &param_value_size));		\
     generic_info info;							\
+    info.dontfree = 0;							\
     info.opaque_class = CLASS_NONE;					\
     info.type = "char*";						\
     info.value = (void*)param_value;					\
@@ -123,6 +126,7 @@
     PYOPENCL_CALL_GUARDED(clGet##WHAT##Info,				\
 			  (FIRST_ARG, SECOND_ARG, sizeof(param_value), param_value, 0)); \
     generic_info info;							\
+    info.dontfree = 0;							\
     info.opaque_class = CLASS_NONE;					\
     info.type = #TYPE"*";						\
       info.value = (void*)param_value;					\
@@ -136,6 +140,7 @@
       ar[i] = VEC[i];							\
     }									\
     generic_info info;							\
+    info.dontfree = 0;							\
     info.opaque_class = CLASS_NONE;					\
     info.type = _copy_str(std::string(#TYPE"[") + tostring(VEC.size()) + "]"); \
     info.value = (void*)ar;						\
@@ -783,6 +788,7 @@ generic_info get_info(cl_device_info param_name) const
 		if(key == 0)
 		  break;
 		generic_info info;
+		info.dontfree = 0;
 		info.opaque_class = CLASS_NONE;
 		switch (key)
 		  {
@@ -806,6 +812,8 @@ generic_info get_info(cl_device_info param_name) const
 #endif
 		    info.type = "intptr_t *";
 		    info.value = (void*)result[i+1];
+		     // we do not own this object
+		    info.dontfree = 1;
 		    break;
 
 #endif
diff --git a/src/c_wrapper/wrap_cl_core.h b/src/c_wrapper/wrap_cl_core.h
index 47e18a49f49b383182c2384cf6dd18b0715392f4..7988ae529d25a1a9e22ab50c21bdf113bcf45651 100644
--- a/src/c_wrapper/wrap_cl_core.h
+++ b/src/c_wrapper/wrap_cl_core.h
@@ -23,6 +23,7 @@ typedef struct {
   class_t opaque_class;
   const char *type;
   void *value;
+  int dontfree;
 } generic_info;