Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
adristef committed Feb 12, 2021
0 parents commit 55dea0e
Show file tree
Hide file tree
Showing 76 changed files with 16,184 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# http://editorconfig.org
root = true

[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[*.yml]
indent_style = space
indent_size = 2
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**Please read the contributing guidelines linked above before opening an issue.**
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**Please read the contributing guidelines linked above before opening a pull request.**
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
!Build/
.last_cover_stats
/META.yml
/META.json
/MYMETA.*
*.o
*.pm.tdy
*.bs

# Devel::Cover
cover_db/

# Devel::NYTProf
nytprof.out

# Dizt::Zilla
/.build/

# Module::Build
_build/
Build
Build.bat

# Module::Install
inc/

# ExtUtils::MakeMaker
/blib/
/_eumm/
/*.gz
/Makefile
/Makefile.old
/MANIFEST.bak
/pm_to_blib
/*.zip
98 changes: 98 additions & 0 deletions AutodlIrssi/ActiveConnections.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is IRC Auto Downloader
#
# The Initial Developer of the Original Code is
# David Nilsson.
# Portions created by the Initial Developer are Copyright (C) 2010, 2011
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# ***** END LICENSE BLOCK *****

#
# Keeps track of all active connections
#

use 5.008;
use strict;
use warnings;

package AutodlIrssi::ActiveConnections;
use AutodlIrssi::Globals;

# Max number of seconds a connection is allowed to be alive before we mark it as a memory leak
use constant MAX_CONNECTION_TIME_SECS => 15*60;

sub new {
my $class = shift;
bless {
connections => {},
nextId => 0,
}, $class;
}

sub cleanUp {
my $self = shift;
}

# Adds the connection, returning a unique id that should be passed to remove(). This method should
# be called in the constructor.
sub add {
my ($self, $obj, $name) = @_;

return unless $AutodlIrssi::g->{options}{memoryLeakCheck};

my $id = $self->{nextId}++;
my $info;
$self->{connections}{$id} = $info = {
time => time(),
class => ref $obj,
name => $name,
};

dmessage 5, "Added connection: id: $id, class: $info->{class}, name: '$info->{name}'";

return $id;
}

# Removes the connection. The $id is the same id returned by add(). Should be called in the dtor.
sub remove {
my ($self, $id) = @_;

return unless $AutodlIrssi::g->{options}{memoryLeakCheck};

if (!exists $self->{connections}{$id}) {
message 0, "ActiveConnections: Could not find id $id";
return;
}

delete $self->{connections}{$id};
dmessage 5, "Removed connection: id: $id";
}

sub reportMemoryLeaks {
my $self = shift;

my $currTime = time();
while (my ($id, $info) = each %{$self->{connections}}) {
if ($currTime - $info->{time} > MAX_CONNECTION_TIME_SECS) {
message 0, "Memory leak: id: $id, class: $info->{class}, name: '$info->{name}'";
delete $self->{connections}{$id};
}
}
}

1;
Loading

0 comments on commit 55dea0e

Please sign in to comment.