fix some memory leaks

This commit is contained in:
chris t 2020-12-24 15:22:48 -08:00
parent 59d9e9c084
commit 6172126b60
2 changed files with 20 additions and 5 deletions

24
fuse.c
View File

@ -25,6 +25,15 @@ static void* do_init(struct fuse_conn_info *conn) {
return c; return c;
} }
static void do_destroy(void *c) {
struct nb_context *nbc = c;
for(int i=0; i<NOISER_COUNT; i++) {
free(nbc->noisers[i]);
}
free(c);
}
static int getattr_root(struct stat *st) { static int getattr_root(struct stat *st) {
st->st_mode = S_IFDIR | 0755; st->st_mode = S_IFDIR | 0755;
st->st_nlink = 2 + NOISER_COUNT; st->st_nlink = 2 + NOISER_COUNT;
@ -46,6 +55,7 @@ static int lookup_path(const char *path, Noiser **n, NoiseFile **nf) {
} }
if(!*n) { if(!*n) {
printf("no noiser\n"); printf("no noiser\n");
free(buf);
return -ENOENT; return -ENOENT;
} }
@ -53,6 +63,7 @@ static int lookup_path(const char *path, Noiser **n, NoiseFile **nf) {
if(!fname) { if(!fname) {
// we already had a valid noiser, so it's fine. // we already had a valid noiser, so it's fine.
printf("returning noiser %p:%s, no fname\n", n, (*n)->name); printf("returning noiser %p:%s, no fname\n", n, (*n)->name);
free(buf);
return 0; return 0;
} }
for(int i=0; i<(*n)->noisefile_count; i++) { for(int i=0; i<(*n)->noisefile_count; i++) {
@ -62,9 +73,11 @@ static int lookup_path(const char *path, Noiser **n, NoiseFile **nf) {
} }
if(*nf) { if(*nf) {
printf("returning fname %p:%s\n", nf, (*nf)->name); printf("returning fname %p:%s\n", nf, (*nf)->name);
free(buf);
return 0; return 0;
} else { } else {
printf("file not found: %s\n", fname); printf("file not found: %s\n", fname);
free(buf);
return -ENOENT; return -ENOENT;
} }
} }
@ -205,7 +218,7 @@ static int do_open(const char* path, struct fuse_file_info* fi) {
if(n->do_open) { if(n->do_open) {
ret = n->do_open(path, fi); ret = n->do_open(path, fi);
append_file_state((struct file_state *)fi->fh); // append_file_state((struct file_state *)fi->fh);
} }
return ret; return ret;
@ -222,10 +235,10 @@ static int do_release(const char *path, struct fuse_file_info *fi) {
return ret; return ret;
} }
if(fi->fh) { // if(fi->fh) {
printf("clearing from statelist\n"); // printf("clearing from statelist\n");
delete_file_state((struct file_state *)fi->fh); // delete_file_state((struct file_state *)fi->fh);
} // }
if(n->do_release) { if(n->do_release) {
printf("noiser-specific cleanup\n"); printf("noiser-specific cleanup\n");
ret = n->do_release(path, fi); ret = n->do_release(path, fi);
@ -344,6 +357,7 @@ static struct fuse_operations ops = {
// void *(*init) (struct fuse_conn_info *conn); // void *(*init) (struct fuse_conn_info *conn);
.init = do_init, .init = do_init,
// void (*destroy) (void *); // void (*destroy) (void *);
.destroy = do_destroy,
// int (*access) (const char *, int); // int (*access) (const char *, int);
// int (*create) (const char *, mode_t, struct fuse_file_info *); // int (*create) (const char *, mode_t, struct fuse_file_info *);
// int (*ftruncate) (const char *, off_t, struct fuse_file_info *); // int (*ftruncate) (const char *, off_t, struct fuse_file_info *);

1
pcg.c
View File

@ -33,6 +33,7 @@ static int do_open(const char *path, struct fuse_file_info *fi) {
state->rng.pcg = &p; state->rng.pcg = &p;
state->next = NULL; state->next = NULL;
state->char_ratio = 4; state->char_ratio = 4;
state->consumed = 0;
fi->fh = (uint64_t)state; fi->fh = (uint64_t)state;
return 0; return 0;