From f4b7f8c5a7a0306c73977330ed87f017f9f773da Mon Sep 17 00:00:00 2001 From: Mark Reynolds Date: Fri, 27 Feb 2015 12:13:26 -0500 Subject: [PATCH] Ticket 48104 - use ns_malloc, etc for memory functions Description: Use the new ns_*alloc/free functions. https://fedorahosted.org/389/ticket/48104 Reviewed by: ? --- ns_thrpool.c | 12 ++++++------ ns_tls.c | 10 +++++----- ns_tls.h | 2 ++ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/ns_thrpool.c b/ns_thrpool.c index 9ee7bfa..99dc004 100644 --- a/ns_thrpool.c +++ b/ns_thrpool.c @@ -184,7 +184,7 @@ internal_ns_job_done(ns_job_t *job) if (job->fd && !NS_JOB_IS_PRESERVE_FD(job->job_type)) { PR_Close(job->fd); } /* else application is responsible for fd */ - PR_DELETE(job); + ns_free(job); } /* @@ -362,13 +362,13 @@ alloc_event_context(size_t size, ns_job_t *job) static void free_event_context(void *ev_ctx, ns_job_t *job) { - free(ev_ctx); + ns_free(ev_ctx); } static ns_job_t * new_ns_job(ns_thrpool_t *tp, PRFileDesc *fd, ns_job_type_t job_type, ns_job_func_t func, struct ns_job_data_t *data) { - ns_job_t *job = PR_NEWZAP(ns_job_t); + ns_job_t *job = ns_calloc(1, sizeof(ns_job_t)); job->tp = tp; job->ns_event_fw_ctx = tp->ns_event_fw_ctx; job->fd = fd; @@ -631,7 +631,7 @@ ns_job_modify(ns_job_t *job, ns_job_type_t job_type) static void ns_thrpool_delete(ns_thrpool_t *tp) { - PR_DELETE(tp); + ns_free(tp); } static ns_thrpool_t * @@ -639,7 +639,7 @@ ns_thrpool_alloc(void) { ns_thrpool_t *tp; - tp = PR_NEWZAP(ns_thrpool_t); + tp = ns_calloc(1, sizeof(struct ns_thrpool_t)); if (NULL == tp) { goto failed; } @@ -812,7 +812,7 @@ ns_thrpool_new(struct ns_thrpool_config *tp_config) setup_event_q_wakeup(tp); for (ii = 0; ii < tp_config->initial_threads; ++ii) { - thr = PR_NEW(ns_thread_t); + thr = ns_calloc(1, sizeof(ns_thread_t)); PR_ASSERT(thr); thr->tp = tp; thr->thr = PR_CreateThread(PR_USER_THREAD, worker_thread_func, diff --git a/ns_tls.c b/ns_tls.c index f5aeed3..50e3d91 100644 --- a/ns_tls.c +++ b/ns_tls.c @@ -21,7 +21,7 @@ typedef struct ns_sec_ctx_t ns_sec_ctx_t; static void errExit(const char *msg) { - fprintf(stderr, msg); + ns_log(LOG_ERR, msg); } static PRFileDesc * @@ -137,12 +137,12 @@ create_tls_model_sock(const char *certname, PRBool is_client) cert = PK11_FindCertFromNickname(certname, NULL); if (cert == NULL) { - fprintf(stderr, "selfserv: Can't find certificate %s\n", certname); + ns_log(LOG_ERR, "selfserv: Can't find certificate %s\n", certname); exit(10); } privKey = PK11_FindKeyByAnyCert(cert, NULL); if (privKey == NULL) { - fprintf(stderr, "selfserv: Can't find Private Key for cert %s\n", certname); + ns_log(LOG_ERR, "selfserv: Can't find Private Key for cert %s\n", certname); exit(11); } certKEA = NSS_FindCertKEAType(cert); @@ -203,14 +203,14 @@ ns_tls_done(ns_sec_ctx_t *ctx) if (ctx->initctx) { NSS_ShutdownContext(ctx->initctx); } - PR_DELETE(ctx); + ns_free(ctx); } ns_sec_ctx_t * ns_tls_init(const char *dir, const char *prefix, const char *certname, PRBool is_client) { SECStatus rc = SECSuccess; - ns_sec_ctx_t *ctx = PR_NEWZAP(ns_sec_ctx_t); + ns_sec_ctx_t *ctx = ns_calloc(1, sizeof(ns_sec_ctx_t)); ctx->init_params.length = sizeof(ctx->init_params); ctx->initctx = NSS_InitContext(dir, prefix, prefix, SECMOD_DB, diff --git a/ns_tls.h b/ns_tls.h index 4c02d51..e889c34 100644 --- a/ns_tls.h +++ b/ns_tls.h @@ -4,6 +4,8 @@ #include "nspr.h" #include "prerror.h" #include "prio.h" +#include "ns_thrpool.h" +#include /* should be in sec_ctx.h */ struct ns_sec_ctx_t; -- 1.9.3