From ed06d0ca0119f68612628a4871632b3a48a187d6 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Sun, 19 Feb 2012 22:48:51 +0000 Subject: [PATCH] object: avoid creating a new entry for NULL data If setting NULL user data via cogl_object_set_user_data() and we fail to find an entry for the given key then bail out before potentially allocating a new entry since setting NULL data is documented to effectively delete an entry. Reviewed-by: Neil Roberts --- cogl/cogl-object.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cogl/cogl-object.c b/cogl/cogl-object.c index 4e0b4edf7..9ae29f756 100644 --- a/cogl/cogl-object.c +++ b/cogl/cogl-object.c @@ -190,6 +190,12 @@ _cogl_object_set_user_data (CoglObject *object, } else { + /* NB: Setting a value of NULL is documented to delete the + * corresponding entry so we can return immediately in this + * case. */ + if (user_data == NULL) + return; + if (G_LIKELY (object->n_user_data_entries < COGL_OBJECT_N_PRE_ALLOCATED_USER_DATA_ENTRIES)) entry = &object->user_data_entry[object->n_user_data_entries++];