xref: /onnv-gate/usr/src/cmd/fs.d/autofs/debug_alloc.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright (c) 1998,2001 by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate  * All rights reserved.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #ifdef	MALLOC_DEBUG
30*0Sstevel@tonic-gate #include <stdlib.h>
31*0Sstevel@tonic-gate #include <stdio.h>
32*0Sstevel@tonic-gate #include <thread.h>
33*0Sstevel@tonic-gate #include <synch.h>
34*0Sstevel@tonic-gate #include <string.h>
35*0Sstevel@tonic-gate #include <stdio.h>
36*0Sstevel@tonic-gate #include <syslog.h>
37*0Sstevel@tonic-gate #include <netdb.h>
38*0Sstevel@tonic-gate #include <netdir.h>
39*0Sstevel@tonic-gate #include <rpc/nettype.h>
40*0Sstevel@tonic-gate 
41*0Sstevel@tonic-gate /*
42*0Sstevel@tonic-gate  * To use debugging facility, compile with * -DMALLOC_DEBUG.
43*0Sstevel@tonic-gate  * You can do this by setting the environment variable
44*0Sstevel@tonic-gate  * MALLOC_DEBUG to "-DMALLOC_DEBUG"
45*0Sstevel@tonic-gate  *
46*0Sstevel@tonic-gate  * To make automountd dump trace records (i.e. make it call check_leaks),
47*0Sstevel@tonic-gate  * run:
48*0Sstevel@tonic-gate  * 	make malloc_dump
49*0Sstevel@tonic-gate  */
50*0Sstevel@tonic-gate 
51*0Sstevel@tonic-gate struct alloc_list
52*0Sstevel@tonic-gate {
53*0Sstevel@tonic-gate 	char type[20];
54*0Sstevel@tonic-gate 	void *addr;
55*0Sstevel@tonic-gate 	int size;
56*0Sstevel@tonic-gate 	char file[80];
57*0Sstevel@tonic-gate 	int line;
58*0Sstevel@tonic-gate 	struct alloc_list *next;
59*0Sstevel@tonic-gate };
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate static struct alloc_list *halist = NULL;
62*0Sstevel@tonic-gate static mutex_t alloc_list_lock = DEFAULTMUTEX;
63*0Sstevel@tonic-gate 
64*0Sstevel@tonic-gate int
add_alloc(char * type,void * addr,size_t size,const char * file,int line)65*0Sstevel@tonic-gate add_alloc(char *type, void *addr, size_t size, const char *file, int line)
66*0Sstevel@tonic-gate {
67*0Sstevel@tonic-gate 	struct alloc_list *alist = NULL;
68*0Sstevel@tonic-gate 
69*0Sstevel@tonic-gate 	/* allocate the list item */
70*0Sstevel@tonic-gate 	alist = (struct alloc_list *)malloc(sizeof (*alist));
71*0Sstevel@tonic-gate 	if (alist == NULL) {
72*0Sstevel@tonic-gate 		syslog(LOG_ERR, "add_alloc: out of memory\n");
73*0Sstevel@tonic-gate 		return (-1);
74*0Sstevel@tonic-gate 	}
75*0Sstevel@tonic-gate 	strcpy(alist->type, type);
76*0Sstevel@tonic-gate 	alist->addr = addr;
77*0Sstevel@tonic-gate 	alist->size = size;
78*0Sstevel@tonic-gate 	strcpy(alist->file, file);
79*0Sstevel@tonic-gate 	alist->line = line;
80*0Sstevel@tonic-gate 
81*0Sstevel@tonic-gate 	/* add it to the head of the list */
82*0Sstevel@tonic-gate 	if (halist == NULL)
83*0Sstevel@tonic-gate 		alist->next = NULL;
84*0Sstevel@tonic-gate 	else
85*0Sstevel@tonic-gate 		alist->next = halist;
86*0Sstevel@tonic-gate 	halist = alist;
87*0Sstevel@tonic-gate 	return (0);
88*0Sstevel@tonic-gate }
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate int
drop_alloc(const char * type,void * addr,const char * file,int line)91*0Sstevel@tonic-gate drop_alloc(const char *type, void *addr, const char *file, int line)
92*0Sstevel@tonic-gate {
93*0Sstevel@tonic-gate 	struct alloc_list *alist, *alist_prev;
94*0Sstevel@tonic-gate 
95*0Sstevel@tonic-gate 	alist = halist;
96*0Sstevel@tonic-gate 	while (alist != NULL) {
97*0Sstevel@tonic-gate 		if (addr == alist->addr) {
98*0Sstevel@tonic-gate 			if (alist == halist)
99*0Sstevel@tonic-gate 				halist = halist->next;
100*0Sstevel@tonic-gate 			else
101*0Sstevel@tonic-gate 				alist_prev->next = alist->next;
102*0Sstevel@tonic-gate 			free(alist);
103*0Sstevel@tonic-gate 			break;
104*0Sstevel@tonic-gate 		}
105*0Sstevel@tonic-gate 		alist_prev = alist;
106*0Sstevel@tonic-gate 		alist = alist->next;
107*0Sstevel@tonic-gate 	}
108*0Sstevel@tonic-gate 
109*0Sstevel@tonic-gate 	if (alist == NULL) {
110*0Sstevel@tonic-gate 		syslog(LOG_ERR, "*** POSSIBLE CORRUPTION ****\n");
111*0Sstevel@tonic-gate 		syslog(LOG_ERR, "\tduplicate free, type %s, at %p in %s/%d\n",
112*0Sstevel@tonic-gate 		    type, addr, file, line);
113*0Sstevel@tonic-gate 		return (-1);
114*0Sstevel@tonic-gate 	}
115*0Sstevel@tonic-gate 	return (0);
116*0Sstevel@tonic-gate }
117*0Sstevel@tonic-gate 
118*0Sstevel@tonic-gate void *
my_malloc(size_t size,const char * file,int line)119*0Sstevel@tonic-gate my_malloc(size_t size, const char *file, int line)
120*0Sstevel@tonic-gate {
121*0Sstevel@tonic-gate 	void *addr;
122*0Sstevel@tonic-gate 
123*0Sstevel@tonic-gate 	addr = (void *)malloc(size);
124*0Sstevel@tonic-gate 	if (addr == NULL)
125*0Sstevel@tonic-gate 		return (NULL);
126*0Sstevel@tonic-gate 	mutex_lock(&alloc_list_lock);
127*0Sstevel@tonic-gate 	add_alloc("MALLOC", addr, size, file, line);
128*0Sstevel@tonic-gate 	mutex_unlock(&alloc_list_lock);
129*0Sstevel@tonic-gate 	return (addr);
130*0Sstevel@tonic-gate }
131*0Sstevel@tonic-gate 
132*0Sstevel@tonic-gate void *
my_realloc(void * addr,size_t size,const char * file,int line)133*0Sstevel@tonic-gate my_realloc(void *addr, size_t size, const char *file, int line)
134*0Sstevel@tonic-gate {
135*0Sstevel@tonic-gate 	void *ptr;
136*0Sstevel@tonic-gate 
137*0Sstevel@tonic-gate 	ptr = (void *)realloc(addr, size);
138*0Sstevel@tonic-gate 	if (ptr == NULL)
139*0Sstevel@tonic-gate 		return (NULL);
140*0Sstevel@tonic-gate 	mutex_lock(&alloc_list_lock);
141*0Sstevel@tonic-gate 	drop_alloc("MALLOC", addr, file, line);
142*0Sstevel@tonic-gate 	add_alloc("MALLOC", ptr, size, file, line);
143*0Sstevel@tonic-gate 	mutex_unlock(&alloc_list_lock);
144*0Sstevel@tonic-gate 
145*0Sstevel@tonic-gate 	return (ptr);
146*0Sstevel@tonic-gate }
147*0Sstevel@tonic-gate 
148*0Sstevel@tonic-gate void
my_free(void * addr,const char * file,int line)149*0Sstevel@tonic-gate my_free(void *addr, const char *file, int line)
150*0Sstevel@tonic-gate {
151*0Sstevel@tonic-gate 	mutex_lock(&alloc_list_lock);
152*0Sstevel@tonic-gate 	drop_alloc("MALLOC", addr, file, line);
153*0Sstevel@tonic-gate 	mutex_unlock(&alloc_list_lock);
154*0Sstevel@tonic-gate 	free(addr);
155*0Sstevel@tonic-gate }
156*0Sstevel@tonic-gate 
157*0Sstevel@tonic-gate char *
my_strdup(const char * straddr,const char * file,int line)158*0Sstevel@tonic-gate my_strdup(const char *straddr, const char *file, int line)
159*0Sstevel@tonic-gate {
160*0Sstevel@tonic-gate 	void *addr;
161*0Sstevel@tonic-gate 	size_t size;
162*0Sstevel@tonic-gate 
163*0Sstevel@tonic-gate 	addr = strdup(straddr);
164*0Sstevel@tonic-gate 	if (addr == NULL)
165*0Sstevel@tonic-gate 		return (NULL);
166*0Sstevel@tonic-gate 	size = strlen(straddr);
167*0Sstevel@tonic-gate 	mutex_lock(&alloc_list_lock);
168*0Sstevel@tonic-gate 	add_alloc("STRDUP", addr, size, file, line);
169*0Sstevel@tonic-gate 	mutex_unlock(&alloc_list_lock);
170*0Sstevel@tonic-gate 
171*0Sstevel@tonic-gate 	return ((char *)addr);
172*0Sstevel@tonic-gate }
173*0Sstevel@tonic-gate 
174*0Sstevel@tonic-gate int
my_sethostent(int stay,const char * file,int line)175*0Sstevel@tonic-gate my_sethostent(int stay, const char *file, int line)
176*0Sstevel@tonic-gate {
177*0Sstevel@tonic-gate 	(void) sethostent(stay);
178*0Sstevel@tonic-gate 	mutex_lock(&alloc_list_lock);
179*0Sstevel@tonic-gate 	add_alloc("SETHOSTENT", NULL, 0, file, line);
180*0Sstevel@tonic-gate 	mutex_unlock(&alloc_list_lock);
181*0Sstevel@tonic-gate 	return (0);
182*0Sstevel@tonic-gate }
183*0Sstevel@tonic-gate 
184*0Sstevel@tonic-gate int
my_endhostent(const char * file,int line)185*0Sstevel@tonic-gate my_endhostent(const char *file, int line)
186*0Sstevel@tonic-gate {
187*0Sstevel@tonic-gate 	int ret;
188*0Sstevel@tonic-gate 
189*0Sstevel@tonic-gate 	ret = endhostent();
190*0Sstevel@tonic-gate 	if (ret != 0)
191*0Sstevel@tonic-gate 		return (ret);
192*0Sstevel@tonic-gate 	mutex_lock(&alloc_list_lock);
193*0Sstevel@tonic-gate 	drop_alloc("SETHOSTENT", NULL, file, line);
194*0Sstevel@tonic-gate 	mutex_unlock(&alloc_list_lock);
195*0Sstevel@tonic-gate 	return (ret);
196*0Sstevel@tonic-gate }
197*0Sstevel@tonic-gate 
198*0Sstevel@tonic-gate void *
my_setnetconfig(const char * file,int line)199*0Sstevel@tonic-gate my_setnetconfig(const char *file, int line)
200*0Sstevel@tonic-gate {
201*0Sstevel@tonic-gate 	void *nconf;
202*0Sstevel@tonic-gate 
203*0Sstevel@tonic-gate 	nconf = setnetconfig();
204*0Sstevel@tonic-gate 	if (nconf == NULL)
205*0Sstevel@tonic-gate 		return (NULL);
206*0Sstevel@tonic-gate 	mutex_lock(&alloc_list_lock);
207*0Sstevel@tonic-gate 	add_alloc("SETNETCONFIG", nconf, 0, file, line);
208*0Sstevel@tonic-gate 	mutex_unlock(&alloc_list_lock);
209*0Sstevel@tonic-gate 	return (nconf);
210*0Sstevel@tonic-gate }
211*0Sstevel@tonic-gate 
212*0Sstevel@tonic-gate int
my_endnetconfig(void * nconf,const char * file,int line)213*0Sstevel@tonic-gate my_endnetconfig(void *nconf, const char *file, int line)
214*0Sstevel@tonic-gate {
215*0Sstevel@tonic-gate 	int res;
216*0Sstevel@tonic-gate 
217*0Sstevel@tonic-gate 	res = endnetconfig(nconf);
218*0Sstevel@tonic-gate 	if (res != 0)
219*0Sstevel@tonic-gate 		return (res);
220*0Sstevel@tonic-gate 	mutex_lock(&alloc_list_lock);
221*0Sstevel@tonic-gate 	drop_alloc("SETNETCONFIG", nconf, file, line);
222*0Sstevel@tonic-gate 	mutex_unlock(&alloc_list_lock);
223*0Sstevel@tonic-gate 	return (0);
224*0Sstevel@tonic-gate }
225*0Sstevel@tonic-gate 
226*0Sstevel@tonic-gate void *
my_setnetpath(const char * file,int line)227*0Sstevel@tonic-gate my_setnetpath(const char *file, int line)
228*0Sstevel@tonic-gate {
229*0Sstevel@tonic-gate 	void *npath;
230*0Sstevel@tonic-gate 
231*0Sstevel@tonic-gate 	npath = setnetpath();
232*0Sstevel@tonic-gate 	if (npath == NULL)
233*0Sstevel@tonic-gate 		return (NULL);
234*0Sstevel@tonic-gate 	mutex_lock(&alloc_list_lock);
235*0Sstevel@tonic-gate 	add_alloc("SETNETPATH", npath, 0, file, line);
236*0Sstevel@tonic-gate 	mutex_unlock(&alloc_list_lock);
237*0Sstevel@tonic-gate 	return (npath);
238*0Sstevel@tonic-gate }
239*0Sstevel@tonic-gate 
240*0Sstevel@tonic-gate int
my_endnetpath(void * npath,const char * file,int line)241*0Sstevel@tonic-gate my_endnetpath(void *npath, const char *file, int line)
242*0Sstevel@tonic-gate {
243*0Sstevel@tonic-gate 	int res;
244*0Sstevel@tonic-gate 
245*0Sstevel@tonic-gate 	res = endnetpath(npath);
246*0Sstevel@tonic-gate 	if (res != 0)
247*0Sstevel@tonic-gate 		return (res);
248*0Sstevel@tonic-gate 	mutex_lock(&alloc_list_lock);
249*0Sstevel@tonic-gate 	drop_alloc("SETNETPATH", npath, file, line);
250*0Sstevel@tonic-gate 	mutex_unlock(&alloc_list_lock);
251*0Sstevel@tonic-gate 	return (0);
252*0Sstevel@tonic-gate }
253*0Sstevel@tonic-gate 
254*0Sstevel@tonic-gate int
my_netdir_getbyname(struct netconfig * tp,struct nd_hostserv * serv,struct nd_addrlist ** addrs,const char * file,int line)255*0Sstevel@tonic-gate my_netdir_getbyname(
256*0Sstevel@tonic-gate 	struct netconfig *tp,
257*0Sstevel@tonic-gate 	struct nd_hostserv *serv,
258*0Sstevel@tonic-gate 	struct nd_addrlist **addrs,
259*0Sstevel@tonic-gate 	const char *file,
260*0Sstevel@tonic-gate 	int line)
261*0Sstevel@tonic-gate {
262*0Sstevel@tonic-gate 	int res;
263*0Sstevel@tonic-gate 
264*0Sstevel@tonic-gate 	res = netdir_getbyname(tp, serv, addrs);
265*0Sstevel@tonic-gate 	if (res != 0)
266*0Sstevel@tonic-gate 		return (res);
267*0Sstevel@tonic-gate 	mutex_lock(&alloc_list_lock);
268*0Sstevel@tonic-gate 	add_alloc("NETDIR_GETBYNAME", *addrs, 0, file, line);
269*0Sstevel@tonic-gate 	mutex_unlock(&alloc_list_lock);
270*0Sstevel@tonic-gate 	return (0);
271*0Sstevel@tonic-gate }
272*0Sstevel@tonic-gate 
273*0Sstevel@tonic-gate void
my_netdir_free(void * ptr,int type,const char * file,int line)274*0Sstevel@tonic-gate my_netdir_free(void *ptr, int type, const char *file, int line)
275*0Sstevel@tonic-gate {
276*0Sstevel@tonic-gate 	netdir_free(ptr, type);
277*0Sstevel@tonic-gate 	mutex_lock(&alloc_list_lock);
278*0Sstevel@tonic-gate 	drop_alloc("NETDIR_GETBYNAME", ptr, file, line);
279*0Sstevel@tonic-gate 	mutex_unlock(&alloc_list_lock);
280*0Sstevel@tonic-gate }
281*0Sstevel@tonic-gate 
282*0Sstevel@tonic-gate struct hostent *
my_getipnodebyname(const char * name,int af,int flags,int * error_num,char * file,int line)283*0Sstevel@tonic-gate my_getipnodebyname(
284*0Sstevel@tonic-gate 	const char *name,
285*0Sstevel@tonic-gate 	int af,
286*0Sstevel@tonic-gate 	int flags,
287*0Sstevel@tonic-gate 	int *error_num,
288*0Sstevel@tonic-gate 	char *file,
289*0Sstevel@tonic-gate 	int line)
290*0Sstevel@tonic-gate {
291*0Sstevel@tonic-gate 	struct hostent *res;
292*0Sstevel@tonic-gate 
293*0Sstevel@tonic-gate 	res = getipnodebyname(name, af, flags, error_num);
294*0Sstevel@tonic-gate 	if (res == NULL)
295*0Sstevel@tonic-gate 		return (NULL);
296*0Sstevel@tonic-gate 	mutex_lock(&alloc_list_lock);
297*0Sstevel@tonic-gate 	add_alloc("GETIPNODEBYNAME", res, 0, file, line);
298*0Sstevel@tonic-gate 	mutex_unlock(&alloc_list_lock);
299*0Sstevel@tonic-gate 	return (res);
300*0Sstevel@tonic-gate }
301*0Sstevel@tonic-gate 
302*0Sstevel@tonic-gate void
my_freehostent(struct hostent * hent,char * file,int line)303*0Sstevel@tonic-gate my_freehostent(struct hostent *hent, char *file, int line)
304*0Sstevel@tonic-gate {
305*0Sstevel@tonic-gate 	freehostent(hent);
306*0Sstevel@tonic-gate 	mutex_lock(&alloc_list_lock);
307*0Sstevel@tonic-gate 	drop_alloc("GETIPNODEBYNAME", hent, file, line);
308*0Sstevel@tonic-gate 	mutex_unlock(&alloc_list_lock);
309*0Sstevel@tonic-gate }
310*0Sstevel@tonic-gate 
311*0Sstevel@tonic-gate struct netconfig *
my_getnetconfigent(char * netid,char * file,int line)312*0Sstevel@tonic-gate my_getnetconfigent(char *netid, char *file, int line)
313*0Sstevel@tonic-gate {
314*0Sstevel@tonic-gate 	struct netconfig *res;
315*0Sstevel@tonic-gate 
316*0Sstevel@tonic-gate 	res = getnetconfigent(netid);
317*0Sstevel@tonic-gate 	if (res == NULL)
318*0Sstevel@tonic-gate 		return (NULL);
319*0Sstevel@tonic-gate 	mutex_lock(&alloc_list_lock);
320*0Sstevel@tonic-gate 	add_alloc("GETNETCONFIGENT", res, 0, file, line);
321*0Sstevel@tonic-gate 	mutex_unlock(&alloc_list_lock);
322*0Sstevel@tonic-gate 	return (res);
323*0Sstevel@tonic-gate }
324*0Sstevel@tonic-gate 
325*0Sstevel@tonic-gate void
my_freenetconfigent(struct netconfig * netp,char * file,int line)326*0Sstevel@tonic-gate my_freenetconfigent(struct netconfig *netp, char *file, int line)
327*0Sstevel@tonic-gate {
328*0Sstevel@tonic-gate 	freenetconfigent(netp);
329*0Sstevel@tonic-gate 	mutex_lock(&alloc_list_lock);
330*0Sstevel@tonic-gate 	drop_alloc("GETNETCONFIGENT", netp, file, line);
331*0Sstevel@tonic-gate 	mutex_unlock(&alloc_list_lock);
332*0Sstevel@tonic-gate }
333*0Sstevel@tonic-gate 
334*0Sstevel@tonic-gate void *
my__rpc_setconf(char * nettype,char * file,int line)335*0Sstevel@tonic-gate my__rpc_setconf(char *nettype, char *file, int line)
336*0Sstevel@tonic-gate {
337*0Sstevel@tonic-gate 	void *res;
338*0Sstevel@tonic-gate 
339*0Sstevel@tonic-gate 	res = __rpc_setconf(nettype);
340*0Sstevel@tonic-gate 	if (res == NULL)
341*0Sstevel@tonic-gate 		return (NULL);
342*0Sstevel@tonic-gate 	mutex_lock(&alloc_list_lock);
343*0Sstevel@tonic-gate 	add_alloc("RPC_SETCONF", res, 0, file, line);
344*0Sstevel@tonic-gate 	mutex_unlock(&alloc_list_lock);
345*0Sstevel@tonic-gate 	return (res);
346*0Sstevel@tonic-gate }
347*0Sstevel@tonic-gate 
348*0Sstevel@tonic-gate void
my__rpc_endconf(void * vhandle,char * file,int line)349*0Sstevel@tonic-gate my__rpc_endconf(void *vhandle, char *file, int line)
350*0Sstevel@tonic-gate {
351*0Sstevel@tonic-gate 	__rpc_endconf(vhandle);
352*0Sstevel@tonic-gate 	mutex_lock(&alloc_list_lock);
353*0Sstevel@tonic-gate 	drop_alloc("RPC_SETCONF", vhandle, file, line);
354*0Sstevel@tonic-gate 	mutex_unlock(&alloc_list_lock);
355*0Sstevel@tonic-gate }
356*0Sstevel@tonic-gate 
357*0Sstevel@tonic-gate extern void flush_caches();
358*0Sstevel@tonic-gate void
_flush_caches()359*0Sstevel@tonic-gate _flush_caches()
360*0Sstevel@tonic-gate {
361*0Sstevel@tonic-gate }
362*0Sstevel@tonic-gate #pragma weak    flush_caches = _flush_caches
363*0Sstevel@tonic-gate 
364*0Sstevel@tonic-gate void
check_leaks(char * filename)365*0Sstevel@tonic-gate check_leaks(char *filename)
366*0Sstevel@tonic-gate {
367*0Sstevel@tonic-gate 	struct alloc_list *alist;
368*0Sstevel@tonic-gate 
369*0Sstevel@tonic-gate 	FILE *fp;
370*0Sstevel@tonic-gate 	fp = fopen(filename, "a");
371*0Sstevel@tonic-gate 	if (fp == NULL) {
372*0Sstevel@tonic-gate 		syslog(LOG_ERR, "check_leaks, could not open file: %s",
373*0Sstevel@tonic-gate 			filename);
374*0Sstevel@tonic-gate 		return;
375*0Sstevel@tonic-gate 	}
376*0Sstevel@tonic-gate 
377*0Sstevel@tonic-gate 	flush_caches();
378*0Sstevel@tonic-gate 	fprintf(fp, "*** POSSIBLE LEAKS ****\n");
379*0Sstevel@tonic-gate 	mutex_lock(&alloc_list_lock);
380*0Sstevel@tonic-gate 	alist = halist;
381*0Sstevel@tonic-gate 	while (alist != NULL) {
382*0Sstevel@tonic-gate 		fprintf(fp, "\t%s: %d bytes at %p in %s/%d\n",
383*0Sstevel@tonic-gate 			alist->type, alist->size, alist->addr,
384*0Sstevel@tonic-gate 			alist->file, alist->line);
385*0Sstevel@tonic-gate 		alist = alist->next;
386*0Sstevel@tonic-gate 	}
387*0Sstevel@tonic-gate 	mutex_unlock(&alloc_list_lock);
388*0Sstevel@tonic-gate 
389*0Sstevel@tonic-gate 	(void) fclose(fp);
390*0Sstevel@tonic-gate }
391*0Sstevel@tonic-gate #else
392*0Sstevel@tonic-gate /*
393*0Sstevel@tonic-gate  * To prevent a compiler warning.
394*0Sstevel@tonic-gate  */
395*0Sstevel@tonic-gate static char filler;
396*0Sstevel@tonic-gate #endif
397