summaryrefslogtreecommitdiffstats
path: root/ini/ini_fileobj.c
diff options
context:
space:
mode:
authorDmitri Pal <dpal@redhat.com>2010-12-20 17:48:59 -0500
committerStephen Gallagher <sgallagh@redhat.com>2010-12-21 11:16:09 -0500
commit32ede0c1400c1393cad1f7a1b06d2bc58e5696f0 (patch)
treec8483a8c362c85827238c18f16e1af488eab9a2c /ini/ini_fileobj.c
parenta88d52ce32a950d466234fb67ce56327094b8e56 (diff)
downloadding-libs2-32ede0c1400c1393cad1f7a1b06d2bc58e5696f0.tar.gz
ding-libs2-32ede0c1400c1393cad1f7a1b06d2bc58e5696f0.tar.xz
ding-libs2-32ede0c1400c1393cad1f7a1b06d2bc58e5696f0.zip
Fix crashes with file object
This patch addresses the crashes with the file object when the file is not there and the file context needs to be destroyed during the open operation.
Diffstat (limited to 'ini/ini_fileobj.c')
-rw-r--r--ini/ini_fileobj.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/ini/ini_fileobj.c b/ini/ini_fileobj.c
index 699026c..94494f7 100644
--- a/ini/ini_fileobj.c
+++ b/ini/ini_fileobj.c
@@ -81,7 +81,7 @@ void ini_config_file_close(struct ini_cfgfile *file_ctx)
free(file_ctx->filename);
col_destroy_collection(file_ctx->error_list);
col_destroy_collection(file_ctx->metadata);
- fclose(file_ctx->file);
+ if(file_ctx->file) fclose(file_ctx->file);
free(file_ctx);
}
@@ -110,7 +110,6 @@ int ini_config_file_open(const char *filename,
return EINVAL;
}
-
/* Allocate structure */
errno = 0;
new_ctx = malloc(sizeof(struct ini_cfgfile));
@@ -120,6 +119,23 @@ int ini_config_file_open(const char *filename,
return error;
}
+
+ new_ctx->filename = NULL;
+ new_ctx->file = NULL;
+ new_ctx->error_list = NULL;
+ new_ctx->metadata = NULL;
+
+ /* TBD - decide whether we actually need an FD.
+ It will be done when we move the metadata
+ processing into this function. */
+ new_ctx->fd = -1;
+
+ /* Store flags */
+ new_ctx->error_level = error_level;
+ new_ctx->collision_flags = collision_flags;
+ new_ctx->metadata_flags = metadata_flags;
+ new_ctx->count = 0;
+
/* Construct the full file path */
errno = 0;
new_ctx->filename = malloc(PATH_MAX + 1);
@@ -143,7 +159,6 @@ int ini_config_file_open(const char *filename,
/* Open file */
TRACE_INFO_STRING("File", new_ctx->filename);
errno = 0;
- new_ctx->file = NULL;
new_ctx->file = fopen(new_ctx->filename, "r");
if (!(new_ctx->file)) {
error = errno;
@@ -152,12 +167,6 @@ int ini_config_file_open(const char *filename,
return error;
}
- /* Store flags */
- new_ctx->error_level = error_level;
- new_ctx->collision_flags = collision_flags;
- new_ctx->metadata_flags = metadata_flags;
- new_ctx->count = 0;
-
/* Create internal collections */
error = col_create_collection(&(new_ctx->error_list),
INI_ERROR,
@@ -177,6 +186,9 @@ int ini_config_file_open(const char *filename,
return error;
}
+
+ /* TBD - Add metadata processing here */
+
*file_ctx = new_ctx;
TRACE_FLOW_EXIT();
return error;