From 528afcc4d6549c42bbba3daf6a11d2ede41a9665 Mon Sep 17 00:00:00 2001 From: Ryan Bloom Date: Tue, 4 Jan 2000 19:01:04 +0000 Subject: [PATCH] Initialize all ap_file_t's to NULL. This allows ap_open and ap_stat to work together without causing memory leaks. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@84393 13f79535-47bb-0310-9956-ffa450edef68 --- modules/filters/mod_include.c | 4 ++-- modules/generators/mod_asis.c | 2 +- modules/generators/mod_autoindex.c | 4 ++-- modules/generators/mod_cgi.c | 6 +++--- modules/generators/mod_cgid.c | 4 ++-- modules/mappers/mod_negotiation.c | 2 +- modules/mappers/mod_rewrite.c | 6 +++--- modules/metadata/mod_mime_magic.c | 4 ++-- server/config.c | 6 +++--- server/log.c | 11 +++++------ server/mpm/prefork/prefork.c | 6 +++--- server/util.c | 2 +- 12 files changed, 28 insertions(+), 29 deletions(-) diff --git a/modules/filters/mod_include.c b/modules/filters/mod_include.c index ecb577b211..445b5d63d7 100644 --- a/modules/filters/mod_include.c +++ b/modules/filters/mod_include.c @@ -823,7 +823,7 @@ static int include_cmd(char *s, request_rec *r) ap_status_t rc; ap_table_t *env = r->subprocess_env; char **argv; - ap_file_t *file; + ap_file_t *file = NULL; ap_iol *iol; arg.r = r; @@ -2347,7 +2347,7 @@ static const char *set_xbithack(cmd_parms *cmd, void *xbp, char *arg) static int send_parsed_file(request_rec *r) { - ap_file_t *f; + ap_file_t *f = NULL; enum xbithack *state = (enum xbithack *) ap_get_module_config(r->per_dir_config, &includes_module); int errstatus; diff --git a/modules/generators/mod_asis.c b/modules/generators/mod_asis.c index e2773405a9..513f619f08 100644 --- a/modules/generators/mod_asis.c +++ b/modules/generators/mod_asis.c @@ -65,7 +65,7 @@ static int asis_handler(request_rec *r) { - ap_file_t *f; + ap_file_t *f = NULL; ap_status_t status; const char *location; diff --git a/modules/generators/mod_autoindex.c b/modules/generators/mod_autoindex.c index 157a75fdd8..ad87eba08f 100644 --- a/modules/generators/mod_autoindex.c +++ b/modules/generators/mod_autoindex.c @@ -939,7 +939,7 @@ static void do_emit_plain(request_rec *r, ap_file_t *f) static void emit_head(request_rec *r, char *header_fname, int suppress_amble, char *title) { - ap_file_t *f; + ap_file_t *f = NULL; request_rec *rr = NULL; int emit_amble = 1; int emit_H1 = 1; @@ -1022,7 +1022,7 @@ static void emit_head(request_rec *r, char *header_fname, int suppress_amble, */ static void emit_tail(request_rec *r, char *readme_fname, int suppress_amble) { - ap_file_t *f; + ap_file_t *f = NULL; request_rec *rr = NULL; int suppress_post = 0; int suppress_sig = 0; diff --git a/modules/generators/mod_cgi.c b/modules/generators/mod_cgi.c index 018e700bc8..4fb6a024d4 100644 --- a/modules/generators/mod_cgi.c +++ b/modules/generators/mod_cgi.c @@ -166,7 +166,7 @@ static const command_rec cgi_cmds[] = static int log_scripterror(request_rec *r, cgi_server_conf * conf, int ret, int show_errno, char *error) { - ap_file_t *f; + ap_file_t *f = NULL; struct stat finfo; ap_log_rerror(APLOG_MARK, show_errno|APLOG_ERR, errno, r, @@ -198,7 +198,7 @@ static int log_script(request_rec *r, cgi_server_conf * conf, int ret, ap_array_header_t *hdrs_arr = ap_table_elts(r->headers_in); ap_table_entry_t *hdrs = (ap_table_entry_t *) hdrs_arr->elts; char argsbuffer[HUGE_STRING_LEN]; - ap_file_t *f; + ap_file_t *f = NULL; int i; struct stat finfo; @@ -285,7 +285,7 @@ static ap_status_t run_cgi_child(BUFF **script_out, BUFF **script_in, BUFF **scr ap_procattr_t *procattr; ap_proc_t *procnew; ap_status_t rc = APR_SUCCESS; - ap_file_t *file; + ap_file_t *file = NULL; ap_iol *iol; #ifdef DEBUG_CGI diff --git a/modules/generators/mod_cgid.c b/modules/generators/mod_cgid.c index ae90d763d4..b3933aa2e2 100644 --- a/modules/generators/mod_cgid.c +++ b/modules/generators/mod_cgid.c @@ -666,7 +666,7 @@ static const command_rec cgid_cmds[] = static int log_scripterror(request_rec *r, cgid_server_conf * conf, int ret, int show_errno, char *error) { - ap_file_t *f; + ap_file_t *f = NULL; struct stat finfo; ap_log_rerror(APLOG_MARK, show_errno|APLOG_ERR, errno, r, @@ -698,7 +698,7 @@ static int log_script(request_rec *r, cgid_server_conf * conf, int ret, ap_array_header_t *hdrs_arr = ap_table_elts(r->headers_in); ap_table_entry_t *hdrs = (ap_table_entry_t *) hdrs_arr->elts; char argsbuffer[HUGE_STRING_LEN]; - ap_file_t *f; + ap_file_t *f = NULL; int i; struct stat finfo; diff --git a/modules/mappers/mod_negotiation.c b/modules/mappers/mod_negotiation.c index 3d69d4564f..14d472a142 100644 --- a/modules/mappers/mod_negotiation.c +++ b/modules/mappers/mod_negotiation.c @@ -776,7 +776,7 @@ static char *lcase_header_name_return_body(char *header, request_rec *r) static int read_type_map(negotiation_state *neg, request_rec *rr) { request_rec *r = neg->r; - ap_file_t *map; + ap_file_t *map = NULL; ap_status_t status; char buffer[MAX_STRING_LEN]; enum header_state hstate; diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c index 1791fdd7da..8c6fc61747 100644 --- a/modules/mappers/mod_rewrite.c +++ b/modules/mappers/mod_rewrite.c @@ -3394,9 +3394,9 @@ static void rewritelock_free(request_rec *r) static void run_rewritemap_programs(server_rec *s, ap_context_t *p) { rewrite_server_conf *conf; - ap_file_t *fpin; - ap_file_t *fpout; - ap_file_t *fperr; + ap_file_t *fpin = NULL; + ap_file_t *fpout = NULL; + ap_file_t *fperr = NULL; ap_array_header_t *rewritemaps; rewritemap_entry *entries; rewritemap_entry *map; diff --git a/modules/metadata/mod_mime_magic.c b/modules/metadata/mod_mime_magic.c index ee553d7a68..f237572ff3 100644 --- a/modules/metadata/mod_mime_magic.c +++ b/modules/metadata/mod_mime_magic.c @@ -935,7 +935,7 @@ static void tryit(request_rec *r, unsigned char *buf, int nb, int checkzmagic) */ static int apprentice(server_rec *s, ap_context_t *p) { - ap_file_t *f; + ap_file_t *f = NULL; ap_status_t result; char line[BUFSIZ + 1]; int errs = 0; @@ -2153,7 +2153,7 @@ static int uncompress_child(struct uncompress_parms *parm, ap_context_t *cntxt, ap_context_t *child_context = cntxt; ap_procattr_t *procattr; ap_proc_t *procnew = NULL; - ap_file_t *file; + ap_file_t *file = NULL; ap_iol *iol; ap_block_alarms(); diff --git a/server/config.c b/server/config.c index be14961683..d0671d0fde 100644 --- a/server/config.c +++ b/server/config.c @@ -1021,20 +1021,20 @@ void ap_process_resource_config(server_rec *s, const char *fname, ap_context_t * { const char *errmsg; cmd_parms parms; - struct stat finfo; + ap_file_t *finfo = NULL; fname = ap_server_root_relative(p, fname); if (!(strcmp(fname, ap_server_root_relative(p, RESOURCE_CONFIG_FILE))) || !(strcmp(fname, ap_server_root_relative(p, ACCESS_CONFIG_FILE)))) { - if (stat(fname, &finfo) == -1) + if (ap_stat(&finfo, fname, ptemp) != APR_SUCCESS) return; } /* don't require conf/httpd.conf if we have a -C or -c switch */ if((ap_server_pre_read_config->nelts || ap_server_post_read_config->nelts) && !(strcmp(fname, ap_server_root_relative(p, SERVER_CONFIG_FILE)))) { - if (stat(fname, &finfo) == -1) + if (ap_stat(&finfo, fname, ptemp) != APR_SUCCESS) return; } diff --git a/server/log.c b/server/log.c index 0180fb0bcf..c0acff4db1 100644 --- a/server/log.c +++ b/server/log.c @@ -204,7 +204,7 @@ static void open_error_log(server_rec *s, ap_context_t *p) int rc; if (*s->error_fname == '|') { - ap_file_t *dummy; + ap_file_t *dummy = NULL; /* This starts a new process... */ rc = log_child (p, s->error_fname+1, &dummy); @@ -299,7 +299,7 @@ void ap_open_logs(server_rec *s_main, ap_context_t *p) } API_EXPORT(void) ap_error_log2stderr(server_rec *s) { - ap_file_t *errfile; + ap_file_t *errfile = NULL; ap_open_stderr(&errfile, s->process->pool); if ( s->error_log != NULL) { @@ -513,8 +513,7 @@ API_EXPORT(void) ap_log_rerror(const char *file, int line, int level, void ap_log_pid(ap_context_t *p, const char *fname) { - ap_file_t *pid_file; - struct stat finfo; + ap_file_t *pid_file = NULL; static pid_t saved_pid = -1; pid_t mypid; @@ -523,7 +522,7 @@ void ap_log_pid(ap_context_t *p, const char *fname) fname = ap_server_root_relative(p, fname); mypid = getpid(); - if (mypid != saved_pid && stat(fname, &finfo) == 0) { + if (mypid != saved_pid && ap_stat(&pid_file, fname, p) == 0) { /* WINCH and HUP call this on each restart. * Only warn on first time through for this pid. * @@ -740,7 +739,7 @@ API_EXPORT(void) ap_close_piped_log(piped_log *pl) API_EXPORT(piped_log *) ap_open_piped_log(ap_context_t *p, const char *program) { piped_log *pl; - ap_file_t *dummy; + ap_file_t *dummy = NULL; int rc; rc = log_child(p, program, &dummy); diff --git a/server/mpm/prefork/prefork.c b/server/mpm/prefork/prefork.c index f4129a00f3..f14f1a9eda 100644 --- a/server/mpm/prefork/prefork.c +++ b/server/mpm/prefork/prefork.c @@ -548,7 +548,7 @@ static int lock_fd = -1; */ static void accept_mutex_init(ap_context_t *p) { - ap_file_t *tempfile; + ap_file_t *tempfile = NULL; lock_it.l_whence = SEEK_SET; /* from current point */ lock_it.l_start = 0; /* -"- */ lock_it.l_len = 0; /* until end of file */ @@ -623,7 +623,7 @@ static ap_status_t accept_mutex_cleanup(void *foo) */ static void accept_mutex_child_init(ap_context_t *p) { - ap_file_t *tempfile; + ap_file_t *tempfile = NULL; ap_status_t ret; ret=ap_open(&tempfile, ap_lock_fname, APR_WRITE, APR_UREAD|APR_UWRITE, p); @@ -641,7 +641,7 @@ static void accept_mutex_child_init(ap_context_t *p) */ static void accept_mutex_init(ap_context_t *p) { - ap_file_t *tempfile; + ap_file_t *tempfile = NULL; ap_status_t ret; expand_lock_fname(p); diff --git a/server/util.c b/server/util.c index 03ccd771b0..9380f28449 100644 --- a/server/util.c +++ b/server/util.c @@ -765,7 +765,7 @@ static void *cfg_getstr(void *buf, size_t bufsiz, void *param) API_EXPORT(ap_status_t) ap_pcfg_openfile(configfile_t **ret_cfg, ap_context_t *p, const char *name) { configfile_t *new_cfg; - ap_file_t *file; + ap_file_t *file = NULL; ap_status_t stat; ap_filetype_e type; -- 2.40.0