diff options
author | Anatol Belski <ab@php.net> | 2017-04-15 19:30:30 +0200 |
---|---|---|
committer | Anatol Belski <ab@php.net> | 2017-04-15 19:32:04 +0200 |
commit | ca543ff01c9e182eadc344aec8746ba19187a2b1 (patch) | |
tree | 471b852ce6837b3cedb41bd20bee3c6a2a069d14 | |
parent | 9719621e078e41aa2d387cea4d4b1dd956c9e1e2 (diff) | |
download | php-git-ca543ff01c9e182eadc344aec8746ba19187a2b1.tar.gz |
improve/fix error handling
GetLastError() should not be called, if the function didn't fail.
-rw-r--r-- | ext/opcache/shared_alloc_win32.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/ext/opcache/shared_alloc_win32.c b/ext/opcache/shared_alloc_win32.c index d05f01cd2b..2701b41739 100644 --- a/ext/opcache/shared_alloc_win32.c +++ b/ext/opcache/shared_alloc_win32.c @@ -134,8 +134,8 @@ static int zend_shared_alloc_reattach(size_t requested_size, char **error_in) FILE *fp = fopen(mmap_base_file, "r"); MEMORY_BASIC_INFORMATION info; - err = GetLastError(); if (!fp) { + err = GetLastError(); zend_win_error_message(ACCEL_LOG_WARNING, mmap_base_file, err); zend_win_error_message(ACCEL_LOG_FATAL, "Unable to open base address file", err); *error_in="fopen"; @@ -184,9 +184,9 @@ static int zend_shared_alloc_reattach(size_t requested_size, char **error_in) } mapping_base = MapViewOfFileEx(memfile, FILE_MAP_ALL_ACCESS, 0, 0, 0, wanted_mapping_base); - err = GetLastError(); if (mapping_base == NULL) { + err = GetLastError(); if (err == ERROR_INVALID_ADDRESS) { zend_win_error_message(ACCEL_LOG_FATAL, "Unable to reattach to base address", err); return ALLOC_FAILURE; @@ -200,7 +200,7 @@ static int zend_shared_alloc_reattach(size_t requested_size, char **error_in) static int create_segments(size_t requested_size, zend_shared_segment ***shared_segments_p, int *shared_segments_count, char **error_in) { - int err, ret; + int err = 0, ret; zend_shared_segment *shared_segment; int map_retries = 0; void *default_mapping_base_set[] = { 0, 0 }; @@ -222,14 +222,14 @@ static int create_segments(size_t requested_size, zend_shared_segment ***shared_ and we have to sleep some time (until the child releases the mapping object) and retry.*/ do { memfile = OpenFileMapping(FILE_MAP_WRITE, 0, create_name_with_username(ACCEL_FILEMAP_NAME)); - err = GetLastError(); if (memfile == NULL) { + err = GetLastError(); break; } ret = zend_shared_alloc_reattach(requested_size, error_in); - err = GetLastError(); if (ret == ALLOC_FAIL_MAPPING) { + err = GetLastError(); /* Mapping failed, wait for mapping object to get freed and retry */ CloseHandle(memfile); memfile = NULL; @@ -256,8 +256,9 @@ static int create_segments(size_t requested_size, zend_shared_segment ***shared_ *shared_segments_count = 1; *shared_segments_p = (zend_shared_segment **) calloc(1, sizeof(zend_shared_segment)+sizeof(void *)); if (!*shared_segments_p) { + err = GetLastError(); zend_shared_alloc_unlock_win32(); - zend_win_error_message(ACCEL_LOG_FATAL, "calloc() failed", GetLastError()); + zend_win_error_message(ACCEL_LOG_FATAL, "calloc() failed", err); *error_in = "calloc"; return ALLOC_FAILURE; } @@ -266,8 +267,8 @@ static int create_segments(size_t requested_size, zend_shared_segment ***shared_ memfile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, requested_size, create_name_with_username(ACCEL_FILEMAP_NAME)); - err = GetLastError(); if (memfile == NULL) { + err = GetLastError(); zend_shared_alloc_unlock_win32(); zend_win_error_message(ACCEL_LOG_FATAL, "Unable to create file mapping", err); *error_in = "CreateFileMapping"; @@ -301,8 +302,8 @@ static int create_segments(size_t requested_size, zend_shared_segment ***shared_ wanted_mapping_base++; } while (!mapping_base); - err = GetLastError(); if (mapping_base == NULL) { + err = GetLastError(); zend_shared_alloc_unlock_win32(); zend_win_error_message(ACCEL_LOG_FATAL, "Unable to create view for file mapping", err); *error_in = "MapViewOfFile"; @@ -310,8 +311,8 @@ static int create_segments(size_t requested_size, zend_shared_segment ***shared_ } else { char *mmap_base_file = get_mmap_base_file(); FILE *fp = fopen(mmap_base_file, "w"); - err = GetLastError(); if (!fp) { + err = GetLastError(); zend_shared_alloc_unlock_win32(); zend_win_error_message(ACCEL_LOG_WARNING, mmap_base_file, err); zend_win_error_message(ACCEL_LOG_FATAL, "Unable to write base address", err); |