]>
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.
20 #include "netdissect-alloc.h"
22 static void nd_add_alloc_list(netdissect_options
*, nd_mem_chunk_t
*);
25 * nd_free_all() is intended to be used after a packet printing
28 /* Add a memory chunk in allocation linked list */
30 nd_add_alloc_list(netdissect_options
*ndo
, nd_mem_chunk_t
*chunkp
)
32 if (ndo
->ndo_last_mem_p
== NULL
) /* first memory allocation */
33 chunkp
->prev_mem_p
= NULL
;
34 else /* previous memory allocation */
35 chunkp
->prev_mem_p
= ndo
->ndo_last_mem_p
;
36 ndo
->ndo_last_mem_p
= chunkp
;
39 /* malloc replacement, with tracking in a linked list */
41 nd_malloc(netdissect_options
*ndo
, size_t size
)
43 nd_mem_chunk_t
*chunkp
= malloc(sizeof(nd_mem_chunk_t
) + size
);
46 nd_add_alloc_list(ndo
, chunkp
);
50 /* Free chunks in allocation linked list from last to first */
52 nd_free_all(netdissect_options
*ndo
)
54 nd_mem_chunk_t
*current
, *previous
;
55 current
= ndo
->ndo_last_mem_p
;
56 while (current
!= NULL
) {
57 previous
= current
->prev_mem_p
;
61 ndo
->ndo_last_mem_p
= NULL
;