From f70be949118a1ed9136224b3a618d95362b24d65 Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Mon, 4 Jan 2016 16:22:48 -0500 Subject: [PATCH] explicitly copy values out of Storage The previously implementation was using `&*` which is now getting optimized by the Go compiler and no longer making a copy. --- tracker/storage.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tracker/storage.go b/tracker/storage.go index dbcd738..839f4a9 100644 --- a/tracker/storage.go +++ b/tracker/storage.go @@ -87,7 +87,8 @@ func (s *Storage) FindTorrent(infohash string) (*models.Torrent, error) { return nil, models.ErrTorrentDNE } - return &*torrent, nil + torrentCopy := *torrent + return &torrentCopy, nil } func (s *Storage) PutTorrent(torrent *models.Torrent) { @@ -98,7 +99,9 @@ func (s *Storage) PutTorrent(torrent *models.Torrent) { if !exists { atomic.AddInt32(&s.size, 1) } - shard.torrents[torrent.Infohash] = &*torrent + + torrentCopy := *torrent + shard.torrents[torrent.Infohash] = &torrentCopy } func (s *Storage) DeleteTorrent(infohash string) { @@ -257,14 +260,16 @@ func (s *Storage) FindUser(passkey string) (*models.User, error) { return nil, models.ErrUserDNE } - return &*user, nil + userCopy := *user + return &userCopy, nil } func (s *Storage) PutUser(user *models.User) { s.usersM.Lock() defer s.usersM.Unlock() - s.users[user.Passkey] = &*user + userCopy := *user + s.users[user.Passkey] = &userCopy } func (s *Storage) DeleteUser(passkey string) {