diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-01-03 19:40:33 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-01-03 20:03:27 +0200 |
commit | fa78a9f21ff4fd85fb568232c9bee957b9c83497 (patch) | |
tree | 597162dff26a81877b5788fc5015fc8b075354b7 /src/verify.c | |
parent | 17f28552af10e72a221a0be16417249852774f1b (diff) | |
download | wydawca-fa78a9f21ff4fd85fb568232c9bee957b9c83497.tar.gz wydawca-fa78a9f21ff4fd85fb568232c9bee957b9c83497.tar.bz2 |
Improve memory management and optimize function signatures.
* src/wydawca.h (file_triplet): New members: relative_dir, obstk.
(virt_tab): Remove spool and reldir from argument lists.
(triplet_strdup): New prototype.
(move_file, archive_file, symlink_file)
(rmsymlink_file, dir_move_file, dir_archive_file)
(dir_symlink_file, dir_rmsymlink_file)
(null_move_file, null_archive_file)
(null_symlink_file, null_rmsymlink_file): Remove spool and reldir
from argument lists.
* src/directive.c (run_check_script): Use trp->obstk to
store the program output.
(process_directives): Update calls to vtab interfaces.
* src/diskio.c (dir_move_file)
(dir_archive_file, dir_symlink_file)
(dir_rmsymlink_file): Remove spool and reldir
arguments. Use the corresponding members of
the struct file_triplet.
* src/null.c (null_move_file, null_archive_file)
(null_symlink_file, null_rmsymlink_file): Likewise.
* src/vtab.c (move_file, archive_file)
(symlink_file, rmsymlink_file): Likewise.
* src/triplet.c (hash_triplet_free): Free obstack and uploader_list.
(triplet_strdup): New function.
(register_file): Initialize trp->obstck.
(fill_project_name): Fill relative_dir as well.
(verify_directive_file): Use triplet_strdup to
keep string values.
Diffstat (limited to 'src/verify.c')
-rw-r--r-- | src/verify.c | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/src/verify.c b/src/verify.c index 01c61ea..93fd28b 100644 --- a/src/verify.c +++ b/src/verify.c @@ -93,7 +93,7 @@ fill_project_name (struct file_triplet *trp) char *blurb; size_t size; FILE *fp; - char *project, *p; + char *p; const char *directory; int rc; @@ -150,23 +150,32 @@ fill_project_name (struct file_triplet *trp) trp->file[file_directive].name); return 1; } - p = strchr (directory, '/'); + + trp->relative_dir = safe_file_name (triplet_strdup (trp, directory)); + if (!trp->relative_dir || trp->relative_dir[0] == '/') + { + logmsg (LOG_ERR, _("%s: invalid directory: %s"), + trp->file[file_directive].name, directory); + return 1; + } + + p = strchr (trp->relative_dir, '/'); if (p) { - size_t len = p - directory; + size_t len = p - trp->relative_dir; if (len == 0) { logmsg (LOG_ERR, _("%s: empty `directory' directive"), trp->file[file_directive].name); return 1; } - project = xmalloc (len + 1); - memcpy (project, directory, len); - project[len] = 0; + obstack_grow (&trp->obstk, trp->relative_dir, len); + obstack_1grow (&trp->obstk, 0); + trp->project = obstack_finish (&trp->obstk); } else - project = xstrdup (directory); - trp->project = xstrdup (project); + trp->project = trp->relative_dir; + return 0; } @@ -254,16 +263,16 @@ verify_directive_file (struct file_triplet *trp) memset (&info, 0, sizeof (info)); p = dictionary_result (dict, md, i, 0); if (p) - info.name = xstrdup (p); + info.name = triplet_strdup (trp, p); p = dictionary_result (dict, md, i, 1); if (p) - info.realname = xstrdup (p); + info.realname = triplet_strdup (trp, p); p = dictionary_result (dict, md, i, 2); if (p) - info.email = xstrdup (p); + info.email = triplet_strdup (trp, p); p = dictionary_result (dict, md, i, 3); if (p) - info.gpg_key = xstrdup (p); + info.gpg_key = triplet_strdup (trp, p); if (debug_level > 3) { @@ -278,10 +287,7 @@ verify_directive_file (struct file_triplet *trp) logmsg (LOG_ERR, _("project-uploader dictionary error: malformed row %lu"), (unsigned long) i); - free (info.name); - free (info.realname); - free (info.gpg_key); - free (info.email); + /* FIXME: Memory not reclaimed */ continue; } |