summaryrefslogtreecommitdiff
path: root/src/cairo-misc.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2008-11-18 17:26:55 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2008-11-29 11:20:34 +0000
commite6963a5bfebda69a1ef0a986cede84bcd955b6d4 (patch)
treea70bd8d15c60a71ba88bdf299244f93aa7b147d0 /src/cairo-misc.c
parentd1801c23fae3777c7c59e084894a3410f7a1f932 (diff)
Mark allocation failures as unlikely.
Use the gcc likelihood annotation to indicate that allocation failures are extremely unlikely.
Diffstat (limited to 'src/cairo-misc.c')
-rw-r--r--src/cairo-misc.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/cairo-misc.c b/src/cairo-misc.c
index c4876031..6f707a66 100644
--- a/src/cairo-misc.c
+++ b/src/cairo-misc.c
@@ -714,14 +714,19 @@ _cairo_intern_string (const char **str_inout, int len)
tmpl.string = (char *) str;
CAIRO_MUTEX_LOCK (_cairo_intern_string_mutex);
- if (_cairo_intern_string_ht == NULL)
+ if (_cairo_intern_string_ht == NULL) {
_cairo_intern_string_ht = _cairo_hash_table_create (_intern_string_equal);
+ if (unlikely (_cairo_intern_string_ht == NULL)) {
+ status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ goto BAIL;
+ }
+ }
istring = _cairo_hash_table_lookup (_cairo_intern_string_ht,
&tmpl.hash_entry);
if (istring == NULL) {
istring = malloc (sizeof (cairo_intern_string_t) + len + 1);
- if (istring != NULL) {
+ if (likely (istring != NULL)) {
istring->hash_entry.hash = tmpl.hash_entry.hash;
istring->len = tmpl.len;
istring->string = (char *) (istring + 1);
@@ -730,17 +735,20 @@ _cairo_intern_string (const char **str_inout, int len)
status = _cairo_hash_table_insert (_cairo_intern_string_ht,
&istring->hash_entry);
- if (unlikely (status))
+ if (unlikely (status)) {
free (istring);
- } else
+ goto BAIL;
+ }
+ } else {
status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ goto BAIL;
+ }
}
- CAIRO_MUTEX_UNLOCK (_cairo_intern_string_mutex);
-
- if (likely (status == CAIRO_STATUS_SUCCESS))
- *str_inout = istring->string;
+ *str_inout = istring->string;
+ BAIL:
+ CAIRO_MUTEX_UNLOCK (_cairo_intern_string_mutex);
return status;
}