summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2020-04-15 19:51:13 +0100
committerFreeArtMan <dos21h@gmail.com>2020-04-15 19:51:13 +0100
commit6c44c2e89000444b1bdf790452fd1b92d121ed06 (patch)
tree8ac22698c6884cccb4c2a658f57755c40ad0740f
parent786bd1e76c6806a4c9272814f9ffe7d901998e4e (diff)
downloadihe-6c44c2e89000444b1bdf790452fd1b92d121ed06.tar.gz
ihe-6c44c2e89000444b1bdf790452fd1b92d121ed06.zip
Cleared one memleak on open/close workflow
-rw-r--r--core.c17
1 files changed, 17 insertions, 0 deletions
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;
}