diff options
author | Peter Zhu <peter@peterzhu.ca> | 2023-06-29 16:31:35 -0400 |
---|---|---|
committer | Peter Zhu <peter@peterzhu.ca> | 2023-06-30 09:13:31 -0400 |
commit | 58386814a7c7275f66ffa111175fca2fe307a1b5 (patch) | |
tree | 56bfd1daec3a6d83dfda64b569de1b9fbbb4d23c /win32/file.c | |
parent | 37a893d12915b8860f6880d6a0c2859e096ab4ff (diff) |
Don't check for null pointer in calls to free
According to the C99 specification section 7.20.3.2 paragraph 2:
> If ptr is a null pointer, no action occurs.
So we do not need to check that the pointer is a null pointer.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/8004
Diffstat (limited to 'win32/file.c')
-rw-r--r-- | win32/file.c | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/win32/file.c b/win32/file.c index 31cc1aff6e..8e6c2c778d 100644 --- a/win32/file.c +++ b/win32/file.c @@ -372,8 +372,7 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na result = append_wstr(result, wpath_pos + 1, user_length_in_path(wpath_pos + 1, wpath_len - 1), path_cp, path_encoding); - if (wpath) - free(wpath); + free(wpath); rb_exc_raise(rb_exc_new_str(rb_eArgError, result)); } @@ -390,7 +389,7 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na const long dir_len = RSTRING_LEN(dir); #if SIZEOF_INT < SIZEOF_LONG if ((long)(int)dir_len != dir_len) { - if (wpath) free(wpath); + free(wpath); rb_raise(rb_eRangeError, "base directory (%ld bytes) is too long", dir_len); } @@ -452,11 +451,8 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na result = rb_str_new_cstr("can't find user "); result = append_wstr(result, wdir_pos + 1, user_length_in_path(wdir_pos + 1, wdir_len - 1), path_cp, path_encoding); - if (wpath) - free(wpath); - - if (wdir) - free(wdir); + free(wpath); + free(wdir); rb_exc_raise(rb_exc_new_str(rb_eArgError, result)); } @@ -573,17 +569,10 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na result = append_wstr(result, wfullpath, size, path_cp, path_encoding); /* TODO: better cleanup */ - if (buffer) - xfree(buffer); - - if (wpath) - free(wpath); - - if (wdir) - free(wdir); - - if (whome) - xfree(whome); + xfree(buffer); + free(wpath); + free(wdir); + xfree(whome); if (wfullpath != wfullpath_buffer) xfree(wfullpath); |