mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Indirectly free(3) buffers in fshutdown(3).
This commit is contained in:
parent
9fec909970
commit
97e1551c81
3 changed files with 6 additions and 3 deletions
|
@ -86,6 +86,7 @@ struct FILE
|
|||
void (*free_func)(void* free_user, struct FILE* fp);
|
||||
/* Application writers shouldn't use anything beyond this point. */
|
||||
pthread_mutex_t file_lock;
|
||||
void (*buffer_free_indirect)(void*);
|
||||
struct FILE* prev;
|
||||
struct FILE* next;
|
||||
int flags;
|
||||
|
|
|
@ -66,5 +66,7 @@ extern "C" int fsetdefaultbuf_unlocked(FILE* fp)
|
|||
|
||||
// The buffer now belongs to the FILE.
|
||||
fp->flags |= _FILE_BUFFER_OWNED;
|
||||
fp->buffer_free_indirect = free;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2013.
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2013, 2014.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
|
@ -34,8 +34,8 @@ extern "C" int fshutdown(FILE* fp)
|
|||
exact error value, for instance, as with popen/pclose. */;
|
||||
}
|
||||
ret = fp->close_func ? fp->close_func(fp->user) : ret;
|
||||
if ( fp->flags & _FILE_BUFFER_OWNED )
|
||||
free(fp->buffer);
|
||||
if ( fp->flags & _FILE_BUFFER_OWNED && fp->buffer_free_indirect )
|
||||
fp->buffer_free_indirect(fp->buffer);
|
||||
// Resetting the FILE here isn't needed in the case where fclose calls us,
|
||||
// but it's nice to zero it out anyway (avoiding state) data, and it's a
|
||||
// feature when called by freopen that wishes to reuse the FILE. It also
|
||||
|
|
Loading…
Reference in a new issue