From 6c44c2e89000444b1bdf790452fd1b92d121ed06 Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Wed, 15 Apr 2020 19:51:13 +0100 Subject: Cleared one memleak on open/close workflow --- core.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'core.c') diff --git a/core.c b/core.c index 7d2600b..91038fc 100644 --- a/core.c +++ b/core.c @@ -112,6 +112,19 @@ int file_open_fn( file_t *ft, const char *filename, int flags ) int ret = 0; int fd; + //check if file is allready initialized or opened + if (ft->fd > 0) + { + printf("Trying to open file but file descriptor allready set\n"); + return -1; + } + + if (ft->filename != NULL) + { + printf("Trying open file, bus structure allready have filename\n"); + return -1; + } + fd = fd_open( filename, flags ); if ( fd < 1 ) { @@ -378,10 +391,14 @@ int file_close( file_t *ft ) { printf("File name is empty\n"); return -1; + } else { + free(ft->filename); + ft->filename = NULL; } fd_close( ft->fd ); memset( ft, 0, sizeof(file_t) ); + ft->fd = -1; return ret; } -- cgit v1.2.3