From b908d72cace0a011612ba312c7b1a746b74cf80d Mon Sep 17 00:00:00 2001 From: Michael Sweet Date: Thu, 14 Sep 2017 14:12:49 -0400 Subject: [PATCH] Fix memory leaks. --- cups/file.c | 2 ++ cups/ipp.c | 16 ++++++++++++++++ cups/thread-private.h | 3 ++- cups/thread.c | 13 ++++++++++++- cups/usersys.c | 4 ++-- test/ipptool.c | 6 ++++-- 6 files changed, 38 insertions(+), 6 deletions(-) diff --git a/cups/file.c b/cups/file.c index 8cdf0368c..5d1505403 100644 --- a/cups/file.c +++ b/cups/file.c @@ -2477,6 +2477,8 @@ cups_fill(cups_file_t *fp) /* I - CUPS file */ * file header... */ + inflateEnd(&fp->stream); + fp->compressed = 0; } else if (status < Z_OK) diff --git a/cups/ipp.c b/cups/ipp.c index 5fd587040..d974bbab8 100644 --- a/cups/ipp.c +++ b/cups/ipp.c @@ -1838,12 +1838,19 @@ ippDelete(ipp_t *ipp) /* I - IPP message */ ipp->use --; if (ipp->use > 0) + { + DEBUG_printf(("4debug_retain: %p IPP message (use=%d)", (void *)ipp, ipp->use)); return; + } + + DEBUG_printf(("4debug_free: %p IPP message", (void *)ipp)); for (attr = ipp->attrs; attr != NULL; attr = next) { next = attr->next; + DEBUG_printf(("4debug_free: %p %s %s%s (%d values)", (void *)attr, attr->name, attr->num_values > 1 ? "1setOf " : "", ippTagString(attr->value_tag), attr->num_values)); + ipp_free_values(attr, 0, attr->num_values); if (attr->name) @@ -1880,6 +1887,8 @@ ippDeleteAttribute( if (!attr) return; + DEBUG_printf(("4debug_free: %p %s %s%s (%d values)", (void *)attr, attr->name, attr->num_values > 1 ? "1setOf " : "", ippTagString(attr->value_tag), attr->num_values)); + /* * Find the attribute in the list... */ @@ -2715,6 +2724,8 @@ ippNew(void) * Set default version - usually 2.0... */ + DEBUG_printf(("4debug_alloc: %p IPP message", (void *)temp)); + if (cg->server_version == 0) _cupsSetDefaults(); @@ -6412,6 +6423,8 @@ ipp_add_attr(ipp_t *ipp, /* I - IPP message */ * Initialize attribute... */ + DEBUG_printf(("4debug_alloc: %p %s %s%s (%d values)", (void *)attr, name, num_values > 1 ? "1setOf " : "", ippTagString(value_tag), num_values)); + if (name) attr->name = _cupsStrAlloc(name); @@ -6968,6 +6981,9 @@ ipp_set_value(ipp_t *ipp, /* IO - IPP message */ * Reset pointers in the list... */ + DEBUG_printf(("4debug_free: %p %s %s%s (%d)", (void *)*attr, (*attr)->name, (*attr)->num_values > 1 ? "1setOf " : "", ippTagString((*attr)->value_tag), (*attr)->num_values)); + DEBUG_printf(("4debug_alloc: %p %s %s%s (%d)", (void *)temp, temp->name, temp->num_values > 1 ? "1setOf " : "", ippTagString(temp->value_tag), temp->num_values)); + if (ipp->current == *attr && ipp->prev) { /* diff --git a/cups/thread-private.h b/cups/thread-private.h index ca4ef4cb4..79d243867 100644 --- a/cups/thread-private.h +++ b/cups/thread-private.h @@ -1,7 +1,7 @@ /* * Private threading definitions for CUPS. * - * Copyright 2009-2016 by Apple Inc. + * Copyright 2009-2017 by Apple Inc. * * These coded instructions, statements, and computer programs are the * property of Apple Inc. and are protected by Federal copyright @@ -99,6 +99,7 @@ extern void _cupsRWLockWrite(_cups_rwlock_t *rwlock); extern void _cupsRWUnlock(_cups_rwlock_t *rwlock); extern void _cupsThreadCancel(_cups_thread_t thread); extern _cups_thread_t _cupsThreadCreate(_cups_thread_func_t func, void *arg); +extern void _cupsThreadDetach(_cups_thread_t thread); extern void *_cupsThreadWait(_cups_thread_t thread); # ifdef __cplusplus diff --git a/cups/thread.c b/cups/thread.c index 77b44426e..7af45ea70 100644 --- a/cups/thread.c +++ b/cups/thread.c @@ -1,7 +1,7 @@ /* * Threading primitives for CUPS. * - * Copyright 2009-2016 by Apple Inc. + * Copyright 2009-2017 by Apple Inc. * * These coded instructions, statements, and computer programs are the * property of Apple Inc. and are protected by Federal copyright @@ -172,6 +172,17 @@ _cupsThreadCreate( } +/* + * '_cupsThreadDetach()' - Tell the OS that the thread is running independently. + */ + +void +_cupsThreadDetach(_cups_thread_t thread)/* I - Thread ID */ +{ + pthread_detach(thread); +} + + /* * '_cupsThreadWait()' - Wait for a thread to exit. */ diff --git a/cups/usersys.c b/cups/usersys.c index ff5cb3083..026b4a7cc 100644 --- a/cups/usersys.c +++ b/cups/usersys.c @@ -1175,7 +1175,7 @@ cups_init_client_conf( * everything...) */ -#ifdef __APPLE__ +#if defined(__APPLE__) && defined(HAVE_SSL) char sval[1024]; /* String value */ int bval; /* Boolean value */ @@ -1196,7 +1196,7 @@ cups_init_client_conf( if (cups_apple_get_boolean(kValidateCertsKey, &bval)) cc->validate_certs = bval; -#endif /* __APPLE__ */ +#endif /* __APPLE__ && HAVE_SSL */ } diff --git a/test/ipptool.c b/test/ipptool.c index 40a71b772..658927ae0 100644 --- a/test/ipptool.c +++ b/test/ipptool.c @@ -3323,8 +3323,7 @@ do_tests(cups_file_t *outfile, /* I - Output file */ } /* - * If we are going to repeat this test, sleep 1 second so we don't flood - * the printer with requests... + * If we are going to repeat this test, display intermediate results... */ if (repeat_test) @@ -3357,6 +3356,9 @@ do_tests(cups_file_t *outfile, /* I - Output file */ { cupsFilePrintf(cupsFileStdout(), " %-68.68s [", name); } + + ippDelete(response); + response = NULL; } } while (repeat_test); -- 2.39.5