X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Ffile-handle-def.c;h=075f7b07901c79150e84b1b27014ca7202270d53;hb=cb08510bbbab7646bc1031427243489024d22a3b;hp=4c4820cb12a08fddfc025890fd1f02afd45bb035;hpb=6e097c89af440da90b43ce90864394c4d0c843d5;p=pspp diff --git a/src/data/file-handle-def.c b/src/data/file-handle-def.c index 4c4820cb12..075f7b0790 100644 --- a/src/data/file-handle-def.c +++ b/src/data/file-handle-def.c @@ -115,12 +115,17 @@ fh_done (void) HMAP_FOR_EACH_SAFE (handle, next, struct file_handle, name_node, &named_handles) unname_handle (handle); + + free_handle (inline_file); } /* Free HANDLE and remove it from the global list. */ static void free_handle (struct file_handle *handle) { + if (handle == NULL) + return; + /* Remove handle from global list. */ if (handle->id != NULL) hmap_delete (&named_handles, &handle->name_node); @@ -153,6 +158,8 @@ unname_handle (struct file_handle *handle) struct file_handle * fh_ref (struct file_handle *handle) { + if (handle == fh_inline_file ()) + return handle; assert (handle->ref_cnt > 0); handle->ref_cnt++; return handle; @@ -165,6 +172,8 @@ fh_unref (struct file_handle *handle) { if (handle != NULL) { + if (handle == fh_inline_file ()) + return; assert (handle->ref_cnt > 0); if (--handle->ref_cnt == 0) free_handle (handle); @@ -215,7 +224,7 @@ create_handle (const char *id, char *handle_name, enum fh_referent referent, struct file_handle *handle = xzalloc (sizeof *handle); handle->ref_cnt = 1; - handle->id = id != NULL ? xstrdup (id) : NULL; + handle->id = xstrdup_if_nonnull (id); handle->name = handle_name; handle->referent = referent; handle->encoding = xstrdup (encoding); @@ -252,7 +261,7 @@ fh_create_file (const char *id, const char *file_name, const char *file_name_enc handle_name = id != NULL ? xstrdup (id) : xasprintf ("`%s'", file_name); handle = create_handle (id, handle_name, FH_REF_FILE, properties->encoding); handle->file_name = xstrdup (file_name); - handle->file_name_encoding = file_name_encoding ? xstrdup (file_name_encoding) : NULL; + handle->file_name_encoding = xstrdup_if_nonnull (file_name_encoding); handle->mode = properties->mode; handle->line_ends = properties->line_ends; handle->record_width = properties->record_width; @@ -409,7 +418,7 @@ fh_set_default_handle (struct file_handle *new_default_handle) fh_unref (default_handle); default_handle = new_default_handle; if (default_handle != NULL) - fh_ref (default_handle); + default_handle = fh_ref (default_handle); } /* Information about a file handle's readers or writers. */ @@ -494,14 +503,14 @@ fh_lock (struct file_handle *h, enum fh_referent mask UNUSED, HMAP_FOR_EACH_WITH_HASH (lock, struct fh_lock, node, hash, &locks) { - if ( 0 == compare_fh_locks (lock, key)) + if (0 == compare_fh_locks (lock, key)) { found_lock = true; break; } } - if ( found_lock ) + if (found_lock) { if (strcmp (lock->type, type)) { @@ -533,7 +542,7 @@ fh_lock (struct file_handle *h, enum fh_referent mask UNUSED, found_lock = false; HMAP_FOR_EACH_WITH_HASH (lock, struct fh_lock, node, hash, &locks) { - if ( 0 == compare_fh_locks (lock, key)) + if (0 == compare_fh_locks (lock, key)) { found_lock = true; break; @@ -608,7 +617,7 @@ fh_is_locked (const struct file_handle *handle, enum fh_access access) HMAP_FOR_EACH_WITH_HASH (k, struct fh_lock, node, hash, &locks) { - if ( 0 == compare_fh_locks (k, &key)) + if (0 == compare_fh_locks (k, &key)) { is_locked = true; break;