diff --git a/phpBB/docs/CHANGELOG.html b/phpBB/docs/CHANGELOG.html
index f596bd0048..9fc81f337b 100644
--- a/phpBB/docs/CHANGELOG.html
+++ b/phpBB/docs/CHANGELOG.html
@@ -109,6 +109,7 @@
[Fix] Incorrect layout when loading PM-draft (Bug #38435 - Patch by nickvergessen)
[Fix] Wrong message shown to user, when adding bots to friends/foes. (Bug #40205 - Patch by nickvergessen)
[Fix] Fix Oracle database backup (Bug #46715)
+ [Fix] Update attachments table when deleting user and retaining his posts. (Bug #40245 - Patch by rxu)
[Change] Change the data format of the default file ACM to be more secure from tampering and have better performance.
[Change] Add index on log_time to the log table to prevent slowdown on boards with many log entries. (Bug #44665 - Patch by bantu)
[Change] Template engine now permits to a limited extent variable includes.
diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php
index ab0122866c..144b323959 100644
--- a/phpBB/includes/functions_user.php
+++ b/phpBB/includes/functions_user.php
@@ -421,6 +421,11 @@ function user_delete($mode, $user_id, $post_username = false)
WHERE topic_last_poster_id = $user_id";
$db->sql_query($sql);
+ $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
+ SET poster_id = ' . ANONYMOUS . "
+ WHERE poster_id = $user_id";
+ $db->sql_query($sql);
+
// Since we change every post by this author, we need to count this amount towards the anonymous user
// Update the post count for the anonymous user