File: mem_leak_test.cpp

package info (click to toggle)
pytango 10.1.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,304 kB
  • sloc: python: 27,795; cpp: 16,150; sql: 252; sh: 152; makefile: 43
file content (22 lines) | stat: -rw-r--r-- 659 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
 * SPDX-FileCopyrightText: All Contributors to the PyTango project
 *
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */

#include "common_header.h"

void force_mem_leak_1234_blocks() {
    // Keep pointers so the compiler can't optimize the allocations away
    static std::vector<void *> leaks;
    leaks.reserve(1234);
    for(int i = 0; i < 1234; ++i) {
        void *block = std::malloc(64);
        leaks.push_back(block);
    }
    std::cout << "Warning: forced memory leak of 1234 blocks for memory leak testing" << std::endl;
}

void export_mem_leak_helper(py::module_ &m) {
    m.def("_force_mem_leak_1234_blocks", &force_mem_leak_1234_blocks);
}