<commit_before>(function() {
    'use strict';
    
    var fs          = require('fs'),
        path        = require('path'),
        Emitter     = require('events').EventEmitter,
        patch       = require('patchfile'),
        ashify      = require('ashify'),
        
        mellow      = require('mellow');
    
    module.exports          = function(sock, options) {
        var emitter = new Emitter();
        
        if (!options)
            options = {
                size: 512000
            };
        
        process.nextTick(function() {
            listen(sock, options, emitter);
        });
        
        return emitter;
    };
    
    function listen(sock, options, emitter) {
        sock.of('/edward')
            .on('connection', function(socket) {
                emitter.on('file', function(name, data) {
                    var filename = mellow.pathFromWin(name);
                    
                    socket.emit('file', filename, data);
                });
                
                emitter.on('error', function(error) {
                    socket.emit('err', error);
                });
                
                socket.on('patch', function(name, data) {
                    name = mellow.pathToWin(name);
                    
                    getHash(name, function(error, hash) {
                        if (error)
                            socket.emit('err', error.message);
                        else
                            patch(name, data, options, function(error) {
                                var msg, baseName;
                                
                                if (error) {
                                    socket.emit('err', error.message);
                                } else {
                                    baseName    = path.basename(name),
                                    msg         = 'patch: ok("' + baseName + '")';
                                    
                                    socket.emit('message', msg);
                                    socket.broadcast.emit('patch', name, data, hash);
                                }
                            });
                    });
                });
                
                emitter.emit('connection');
            });
    }
    
    function getHash(name, callback) {<commit_msg>fix(socket) memory leack: listeners do not removed after disconnect<commit_after>(function() {
    'use strict';
    
    var fs          = require('fs'),
        path        = require('path'),
    
        Emitter     = require('events').EventEmitter,
        patch       = require('patchfile'),
        ashify      = require('ashify'),
        
        mellow      = require('mellow');
    
    module.exports          = function(sock, options) {
        var emitter = new Emitter();
        
        if (!options)
            options = {
                size: 512000
            };
        
        process.nextTick(function() {
            listen(sock, options, emitter);
        });
        
        return emitter;
    };
    
    function listen(sock, options, emitter) {
        sock.of('/edward')
            .on('connection', function(socket) {
                var onError = function(error) {
                        socket.emit('err', error);
                    },
                    onFile  = function(name, data) {
                        var filename = mellow.pathFromWin(name);
                        
                        socket.emit('file', filename, data);
                    };
                
                emitter.on('error', onError);
                
                emitter.on('file', onFile);
                
                socket.on('patch', function(name, data) {
                    name = mellow.pathToWin(name);
                    
                    getHash(name, function(error, hash) {
                        if (error)
                            socket.emit('err', error.message);
                        else
                            patch(name, data, options, function(error) {
                                var msg, baseName;
                                
                                if (error) {
                                    socket.emit('err', error.message);
                                } else {
                                    baseName    = path.basename(name),
                                    msg         = 'patch: ok("' + baseName + '")';
                                    
                                    socket.emit('message', msg);
                                    socket.broadcast.emit('patch', name, data, hash);
                                }
                            });
                    });
                });
                
                emitter.emit('connection');
                
                socket.on('disconnect', function() {
                    emitter.removeListener('error', onError);
                    emitter.removeListener('file', onFile);
                });
            });
    }
    
    function getHash(name, callback) {
{'fraction_non_alphanumeric': 0.10507880910683012, 'fraction_numerical': 0.002335084646818447, 'mean_word_length': 0.8403150733977801, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '727676', 'n_tokens_mistral': 1184, 'n_tokens_neox': 1092, 'n_words': 209}