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