Commit 5e3c41b0 by Celine Mercier

C: Fixed opened DIR leak

parent b3a1011d
......@@ -23,6 +23,7 @@ from obitools3.dms.capi.obiview cimport NUC_SEQUENCE_COLUMN, \
import shutil
import string
import random
#import subprocess
VIEW_TYPES = [b"", b"NUC_SEQS_VIEW"]
......@@ -516,6 +517,10 @@ def run(config):
i+=1
if (i%(config['test']['nbtests']/10)) == 0 :
print("Testing......"+str(i*100/config['test']['nbtests'])+"%")
#lsof = subprocess.Popen("lsof | grep '/private/tmp/test_dms.obidms/'", stdin=subprocess.PIPE, shell=True )
#lsof.communicate( b"LSOF\n" )
#lsof = subprocess.Popen("lsof | wc -l", stdin=subprocess.PIPE, shell=True )
#lsof.communicate( b"LSOF total\n" )
#print(infos)
......
......@@ -368,11 +368,18 @@ static obiversion_t obi_get_new_version_number(OBIDMS_column_directory_p column_
if (version_file_descriptor < 0)
{
if (errno == ENOENT)
{
free(version_file_name);
free(column_directory_name);
closedir(col_directory);
return create_version_file(column_directory);
}
else
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
obidebug(1, "\nError opening a version file");
free(column_directory_name);
closedir(col_directory);
free(version_file_name);
return -1;
}
......@@ -380,7 +387,13 @@ static obiversion_t obi_get_new_version_number(OBIDMS_column_directory_p column_
free(version_file_name);
free(column_directory_name);
closedir(col_directory);
if (closedir(col_directory) < 0)
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
obidebug(1, "\nError opening a version file");
close(version_file_descriptor);
return -1;
}
// Test if the version file size is ok
if (lseek(version_file_descriptor, 0, SEEK_END) < loc_size)
......@@ -1193,7 +1206,13 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
free(column_file_name);
free(column_directory_name);
closedir(col_dir);
if (closedir(col_dir) < 0)
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
obidebug(1, "\nError closing a column directory");
close(column_file_descriptor);
return NULL;
}
// Truncate the column file to the right size
if (ftruncate(column_file_descriptor, file_size) < 0)
......@@ -1453,7 +1472,13 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
free(column_file_name);
free(column_directory_name);
closedir(col_dir);
if (closedir(col_dir) < 0)
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
obidebug(1, "\nError closing a column directory");
close(column_file_descriptor);
return NULL;
}
// Allocate the memory for the column structure
column = (OBIDMS_column_p) malloc(sizeof(OBIDMS_column_t));
......@@ -1807,7 +1832,13 @@ int obi_truncate_column(OBIDMS_column_p column) // TODO is it necessary to unmap
free(column_file_name);
free(column_directory_name);
closedir(col_dir);
if (closedir(col_dir) < 0)
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
obidebug(1, "\nError closing a column directory");
close(column_file_descriptor);
return -1;
}
// Unmap the data before truncating the file
if (munmap(column->data, (column->header)->data_size) < 0)
......@@ -1932,7 +1963,13 @@ int obi_enlarge_column(OBIDMS_column_p column)
free(column_file_name);
free(column_directory_name);
closedir(col_dir);
if (closedir(col_dir) < 0)
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
obidebug(1, "\nError closing a column directory");
close(column_file_descriptor);
return -1;
}
// Calculate the new file size
old_line_count = (column->header)->line_count;
......@@ -2227,7 +2264,13 @@ OBIDMS_column_header_p obi_column_get_header_from_name(OBIDMS_p dms, const char*
free(column_file_name);
free(column_directory_name);
closedir(col_dir);
if (closedir(col_dir) < 0)
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
obidebug(1, "\nError closing a column directory");
close(column_file_descriptor);
return NULL;
}
// Read the header size
if (read(column_file_descriptor, &header_size, sizeof(size_t)) < ((ssize_t) sizeof(size_t)))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment