| 281 | */ |
| 282 | |
| 283 | void |
| 284 | _cupsStrFree(const char *s) /* I - String to free */ |
| 285 | { |
| 286 | _cups_sp_item_t *item, /* String pool item */ |
| 287 | *key; /* Search key */ |
| 288 | |
| 289 | |
| 290 | /* |
| 291 | * Range check input... |
| 292 | */ |
| 293 | |
| 294 | if (!s) |
| 295 | return; |
| 296 | |
| 297 | /* |
| 298 | * Check the string pool... |
| 299 | * |
| 300 | * We don't need to lock the mutex yet, as we only want to know if |
| 301 | * the stringpool is initialized. The rest of the code will still |
| 302 | * work if it is initialized before we lock... |
| 303 | */ |
| 304 | |
| 305 | if (!stringpool) |
| 306 | return; |
| 307 | |
| 308 | /* |
| 309 | * See if the string is already in the pool... |
| 310 | */ |
| 311 | |
| 312 | _cupsMutexLock(&sp_mutex); |
| 313 | |
| 314 | key = (_cups_sp_item_t *)(s - offsetof(_cups_sp_item_t, str)); |
| 315 | |
| 316 | if ((item = (_cups_sp_item_t *)cupsArrayFind(stringpool, key)) != NULL && |
| 317 | item == key) |
| 318 | { |
| 319 | /* |
| 320 | * Found it, dereference... |
| 321 | */ |
| 322 | |
| 323 | #ifdef DEBUG_GUARDS |
| 324 | if (key->guard != _CUPS_STR_GUARD) |
| 325 | { |
| 326 | DEBUG_printf(("5_cupsStrFree: Freeing string %p(%s), guard=%08x, ref_count=%d", key, key->str, key->guard, key->ref_count)); |
| 327 | abort(); |
| 328 | } |
| 329 | #endif /* DEBUG_GUARDS */ |
| 330 | |
| 331 | item->ref_count --; |
| 332 | |
| 333 | if (!item->ref_count) |
| 334 | { |
| 335 | /* |
| 336 | * Remove and free... |
| 337 | */ |
| 338 | |
| 339 | cupsArrayRemove(stringpool, item); |
| 340 |
no test coverage detected