]>
The Tcpdump Group git mirrors - tcpdump/blob - netdissect-alloc.c
2 * Copyright (c) 2018 The TCPDUMP project
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code
7 * distributions retain the above copyright notice and this paragraph
8 * in its entirety, and (2) distributions including binary code include
9 * the above copyright notice and this paragraph in its entirety in
10 * the documentation or other materials provided with the distribution.
11 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
12 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
13 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 * FOR A PARTICULAR PURPOSE.
22 #include "netdissect-alloc.h"
24 static void nd_add_alloc_list(netdissect_options
*, nd_mem_chunk_t
*);
27 * nd_free_all() is intended to be used after a packet printing
30 /* Add a memory chunk in allocation linked list */
32 nd_add_alloc_list(netdissect_options
*ndo
, nd_mem_chunk_t
*chunkp
)
34 if (ndo
->ndo_last_mem_p
== NULL
) /* first memory allocation */
35 chunkp
->prev_mem_p
= NULL
;
36 else /* previous memory allocation */
37 chunkp
->prev_mem_p
= ndo
->ndo_last_mem_p
;
38 ndo
->ndo_last_mem_p
= chunkp
;
41 /* malloc replacement, with tracking in a linked list */
43 nd_malloc(netdissect_options
*ndo
, size_t size
)
45 nd_mem_chunk_t
*chunkp
= malloc(sizeof(nd_mem_chunk_t
) + size
);
48 nd_add_alloc_list(ndo
, chunkp
);
52 /* Free chunks in allocation linked list from last to first */
54 nd_free_all(netdissect_options
*ndo
)
56 nd_mem_chunk_t
*current
, *previous
;
57 current
= ndo
->ndo_last_mem_p
;
58 while (current
!= NULL
) {
59 previous
= current
->prev_mem_p
;
63 ndo
->ndo_last_mem_p
= NULL
;