]> git.lizzy.rs Git - plan9front.git/blob - sys/src/lib9p/mem.c
lib9p: zero out per connection state in Srv template for listensrv()
[plan9front.git] / sys / src / lib9p / mem.c
1 #include <u.h>
2 #include <libc.h>
3 #include <auth.h>
4 #include <fcall.h>
5 #include <thread.h>
6 #include "9p.h"
7
8 void*
9 emalloc9p(ulong sz)
10 {
11         void *v;
12
13         if((v = malloc(sz)) == nil) {
14                 fprint(2, "out of memory allocating %lud\n", sz);
15                 exits("mem");
16         }
17         memset(v, 0, sz);
18         setmalloctag(v, getcallerpc(&sz));
19         return v;
20 }
21
22 void*
23 erealloc9p(void *v, ulong sz)
24 {
25         void *nv;
26
27         if((nv = realloc(v, sz)) == nil && sz != 0) {
28                 fprint(2, "out of memory allocating %lud\n", sz);
29                 exits("mem");
30         }
31         if(v == nil)
32                 setmalloctag(nv, getcallerpc(&v));
33         setrealloctag(nv, getcallerpc(&v));
34         return nv;
35 }
36
37 char*
38 estrdup9p(char *s)
39 {
40         char *t;
41
42         if((t = strdup(s)) == nil) {
43                 fprint(2, "out of memory in strdup(%.10s)\n", s);
44                 exits("mem");
45         }
46         setmalloctag(t, getcallerpc(&s));
47         return t;
48 }
49