FreeBSD Bugzilla – Attachment 218038 Details for
Bug 249416
Each call to newlocale(3) with a non-null base argument results in additional memory usage
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
newlocale() test program
localetest.c (text/plain), 3.83 KB, created by
Craig Leres
on 2020-09-18 01:33:46 UTC
(
hide
)
Description:
newlocale() test program
Filename:
MIME Type:
Creator:
Craig Leres
Created:
2020-09-18 01:33:46 UTC
Size:
3.83 KB
patch
obsolete
>/* @(#) $Id: localetest.c 1640 2020-09-18 01:24:57Z leres $ (LBL) */ > >#include <sys/types.h> >#include <sys/sysctl.h> >#include <sys/user.h> > >#include <errno.h> >#include <locale.h> >#include <stdio.h> >#include <stdlib.h> >#include <string.h> >#include <sysexits.h> >#include <unistd.h> > >#ifdef __FreeBSD__ >#define MEMDEBUG() memdebug(__FILE__, __LINE__) >#else >#define MEMDEBUG() do {} while(0) >#endif > >#ifdef __FreeBSD__ >extern void memdebug(const char *, int); >#endif > >/* Forwards */ >int main(int, char **); >void usage(void) __attribute__((noreturn)); >#ifdef __FreeBSD__ >static void _check(const char *, int, segsz_t, vm_size_t); >static void _fetch(segsz_t *, vm_size_t *); >#endif > >/* Globals */ >int debug; >int repeat = 10000000; >int workaround; >int dosleep; >int domemcheck; >const char *prog; > >/* Locals */ >#ifdef __FreeBSD__ >static segsz_t last_rss; >static vm_size_t last_vsz; >#endif > >int >main(int argc, char **argv) >{ > int i, op, ret; > long uv; > char *cp, *ep; > locale_t oldlocale; > > if (argv[0] == NULL) > prog = "jsontest"; > else if ((cp = strrchr(argv[0], '/')) != NULL) > prog = cp + 1; > else > prog = argv[0]; > > opterr = 0; > while ((op = getopt(argc, argv, "dmwr:")) != EOF) > switch (op) { > > case 'd': > ++debug; > break; > > case 'm': > ++domemcheck; > break; > > case 'r': > uv = strtol(optarg, &ep, 10); > if (uv < 1 || *ep != '\0') { > fprintf(stderr, > "%s: bad -r repeat value \"%s\"\n", > prog, optarg); > exit(1); > } > repeat = uv; > break; > > case 's': > dosleep = 1; > break; > > case 'w': > ++workaround; > break; > > default: > usage(); > /* NOTREACHED */ > } > > if (argc != optind) > usage(); > > fprintf(stderr, "######## %s pid %d\n", prog, getpid()); > > ret = 0; > oldlocale = uselocale(NULL); > for (i = 0; i < repeat; ++i) { > locale_t duploc = duplocale(oldlocale); > MEMDEBUG(); > locale_t newloc = newlocale(LC_NUMERIC_MASK, "C", duploc); > MEMDEBUG(); > if (workaround) { > freelocale(duploc); // Should not be needed > MEMDEBUG(); > } > freelocale(newloc); > MEMDEBUG(); > } > > if (dosleep) > for (;;) > sleep(60); > exit(ret); >} > >void >usage(void) >{ > fprintf(stderr, "Usage: %s [-dw] [-r N]\n", prog); > exit(EX_USAGE); >} > >#ifdef __FreeBSD__ >static void >_check(const char *sn, int line, segsz_t rss, vm_size_t vsz) >{ > if (last_rss == 0 || last_vsz == 0) { > fprintf(stderr, "%s:%d initial rss=%zu, vsz=%zu\n", > sn, line, rss, vsz); > fflush(stderr); > last_rss = rss; > last_vsz = vsz; > } > if (last_rss != rss || last_vsz != vsz) { > fprintf(stderr, "%s:%d", sn, line); > if (last_rss != rss) { > fprintf(stderr, " rss %zu -> %zu", last_rss, rss); > last_rss = rss; > } > if (last_vsz != vsz) { > fprintf(stderr, " vsz %zu -> %zu", last_vsz, vsz); > last_vsz = vsz; > } > fprintf(stderr, "\n"); > fflush(stderr); > } >} > >#define XNAMELEN 4 > >static void >_fetch(segsz_t *rssp, vm_size_t *vszp) >{ > struct kinfo_proc *kipp; > int mib[XNAMELEN]; > size_t len; > pid_t pid; > > pid = getpid(); > > len = 0; > mib[0] = CTL_KERN; > mib[1] = KERN_PROC; > mib[2] = KERN_PROC_PID; > mib[3] = pid; > if (sysctl(mib, XNAMELEN, NULL, &len, NULL, 0) < 0) { > fprintf(stderr, "sysctl 1: %s\n", strerror(errno)); > exit(1); > } > > kipp = malloc(len); > if (kipp == NULL) { > fprintf(stderr, "malloc: %s\n", strerror(errno)); > exit(1); > } > > if (sysctl(mib, XNAMELEN, kipp, &len, NULL, 0) < 0) { > fprintf(stderr, "sysctl 2: %s\n", strerror(errno)); > exit(1); > } > > if (len != sizeof(*kipp)) { > fprintf(stderr, "bad size 1\n"); > exit(1); > } > if (kipp->ki_structsize != sizeof(*kipp)) { > fprintf(stderr, "bad size 1\n"); > exit(1); > } > if (kipp->ki_pid != pid) { > fprintf(stderr, "bad pid 1\n"); > exit(1); > } > > *rssp = kipp->ki_rssize; > *vszp = kipp->ki_size; > free(kipp); >} > >void >memdebug(const char *fn, int line) >{ > const char *sn; > segsz_t rss; > vm_size_t vsz; > > sn = strrchr(fn, '/'); > if (sn != NULL) > ++sn; > else > sn = fn; > > _fetch(&rss, &vsz); > _check(sn, line, rss, vsz); >} >#endif
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 249416
: 218038 |
218084