From commits-return-47656-archive-asf-public=cust-asf.ponee.io@qpid.apache.org Wed Dec 19 15:24:21 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 16EC3180670 for ; Wed, 19 Dec 2018 15:24:20 +0100 (CET) Received: (qmail 25562 invoked by uid 500); 19 Dec 2018 14:24:20 -0000 Mailing-List: contact commits-help@qpid.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@qpid.apache.org Delivered-To: mailing list commits@qpid.apache.org Received: (qmail 25553 invoked by uid 99); 19 Dec 2018 14:24:20 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Dec 2018 14:24:20 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 7EFFD80584; Wed, 19 Dec 2018 14:24:19 +0000 (UTC) Date: Wed, 19 Dec 2018 14:24:19 +0000 To: "commits@qpid.apache.org" Subject: [qpid-dispatch] branch master updated: DISPATCH-1225: fill freed memory with a pattern for debugging MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <154522945944.20877.9063541688239525090@gitbox.apache.org> From: kgiusti@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: qpid-dispatch X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: b952edc093113f9b9ecada9df46322d09fdd0e87 X-Git-Newrev: 94e484f964b38891e70b5d74ba9afaf7859dc151 X-Git-Rev: 94e484f964b38891e70b5d74ba9afaf7859dc151 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated This is an automated email from the ASF dual-hosted git repository. kgiusti pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git The following commit(s) were added to refs/heads/master by this push: new 94e484f DISPATCH-1225: fill freed memory with a pattern for debugging 94e484f is described below commit 94e484f964b38891e70b5d74ba9afaf7859dc151 Author: Kenneth Giusti AuthorDate: Tue Dec 18 09:45:07 2018 -0500 DISPATCH-1225: fill freed memory with a pattern for debugging This closes #426 --- include/qpid/dispatch/alloc.h | 13 +++++++++++++ include/qpid/dispatch/alloc_malloc.h | 12 +++++++++--- src/alloc_pool.c | 7 +++---- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/include/qpid/dispatch/alloc.h b/include/qpid/dispatch/alloc.h index 1f6a3c8..3ee4566 100644 --- a/include/qpid/dispatch/alloc.h +++ b/include/qpid/dispatch/alloc.h @@ -20,6 +20,19 @@ */ #include "config.h" +#include + + +#if !defined(NDEBUG) +#define QD_MEMORY_DEBUG 1 +// when debugging fill allocated/deallocated memory +// to catch uinitialized access or use after free +#define QD_MEMORY_FREE 0x99 +#define QD_MEMORY_INIT 0x11 +#define QD_MEMORY_FILL(P,C,S) do { if (P) { memset((P),(C),(S)); } } while (0) +#else +#define QD_MEMORY_FILL(P,C,S) +#endif #if USE_MEMORY_POOL #include "alloc_pool.h" diff --git a/include/qpid/dispatch/alloc_malloc.h b/include/qpid/dispatch/alloc_malloc.h index 3ba6cf3..12d683e 100644 --- a/include/qpid/dispatch/alloc_malloc.h +++ b/include/qpid/dispatch/alloc_malloc.h @@ -20,6 +20,7 @@ */ #include +#include /** *@file @@ -32,9 +33,14 @@ T *new_##T(void); \ void free_##T(T *p) -#define ALLOC_DEFINE_CONFIG(T,S,A,C) \ - T *new_##T(void) { size_t *a = (A); return (T*) malloc((S)+ (a ? *a : 0)); } \ - void free_##T(T *p) { free(p); } \ +#define ALLOC_DEFINE_CONFIG(T,S,A,C) \ + T *new_##T(void) { size_t *a = (A); \ + T *p = malloc((S)+ (a ? *a : 0)); \ + QD_MEMORY_FILL(p, QD_MEMORY_INIT, (S) + (a ? *a : 0)); \ + return p; } \ + void free_##T(T *p) { size_t *a = (A); \ + QD_MEMORY_FILL(p, QD_MEMORY_FREE, (S) + (a ? *a : 0)); \ + free(p); } \ void *unused##T #define ALLOC_DEFINE(T) ALLOC_DEFINE_CONFIG(T, sizeof(T), 0, 0) diff --git a/src/alloc_pool.c b/src/alloc_pool.c index 170fd57..28e8da3 100644 --- a/src/alloc_pool.c +++ b/src/alloc_pool.c @@ -28,10 +28,6 @@ #include "entity_cache.h" #include "config.h" -#if !defined(NDEBUG) -#define QD_MEMORY_DEBUG 1 -#endif - const char *QD_ALLOCATOR_TYPE = "allocator"; typedef struct qd_alloc_type_t qd_alloc_type_t; @@ -149,6 +145,7 @@ void *qd_alloc(qd_alloc_type_desc_t *desc, qd_alloc_pool_t **tpool) item->desc = desc; item->header = PATTERN_FRONT; *((uint32_t*) ((char*) &item[1] + desc->total_size))= PATTERN_BACK; + QD_MEMORY_FILL(&item[1], QD_MEMORY_INIT, desc->total_size); #endif return &item[1]; } @@ -202,6 +199,7 @@ void *qd_alloc(qd_alloc_type_desc_t *desc, qd_alloc_pool_t **tpool) item->desc = desc; item->header = PATTERN_FRONT; *((uint32_t*) ((char*) &item[1] + desc->total_size))= PATTERN_BACK; + QD_MEMORY_FILL(&item[1], QD_MEMORY_INIT, desc->total_size); #endif return &item[1]; } @@ -224,6 +222,7 @@ void qd_dealloc(qd_alloc_type_desc_t *desc, qd_alloc_pool_t **tpool, char *p) assert (*((uint32_t*) (p + desc->total_size)) == PATTERN_BACK); assert (item->desc == desc); // Check for double-free item->desc = 0; + QD_MEMORY_FILL(p, QD_MEMORY_FREE, desc->total_size); #endif // --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org For additional commands, e-mail: commits-help@qpid.apache.org