Memory leak in CPP module - visual-c++

I have a cpp service which is built using cxx file. How can I analyze memory leak in this file using CRT library?
Tried with adding
#define new new(_NORMAL_BLOCK_,__FILE__,__LINE__)
But its showing error.
Is that the same way?

Try this:
#define DEBUG_NEW new(__FILE__, __LINE__)
#define new DEBUG_NEW

Related

C++ Project have lib files but it gives missing *.dll error when starting

Hello Professional Developer Community.
I'm a C# and Android developer. I don't understand much from C++.
I have a C++ Win32 project. I think it's written with VS 2015.
Project have two static libraries (LuaLibDll.lib and LuaScriptVM.lib)
Lib files have been added to the Linker>Input and have header files(.h).
The compilation is successful but gives me an error when starting the Win32 program.
The program can't start because LuaLib.dll (and LuaScriptMV.dll) is
missing from your computer.Try reinstalling the program to fix this
problem.
Note:
Project does not create dll(s).
These codes are added in LuaLib.h and LuScriptVM.h
#ifndef __linux
#ifdef LUASCRIPTVM_EXPORTS
#define _LUAVM __declspec(dllexport)
#else
#define _LUAVM __declspec(dllimport)
#endif
#else
#define _LUAVM
#endif
Thank you for your interest

Sony device has different kernel config than source. Why?

I tried to build simple kernel module (using source downloaded from developer.sonymobile.com) but after compiling i can't insmod it: Unknown symbol __gnu_mcount_nc so i founded a solution and I wrote another module using assembler and I exported this function. After this module insmoded correctly but I see in lsmod that all modules are permament. I have a problem with simple filesystem (Permission denied - default action when pointer is null), on PC this code works without any errors.
I guess the config is wrong in source code, (probably offset of some fields in structure is another than in device).
Version of built is: 24.0.A.5.14 (downloaded from developer.sonymobile.com site).
Can I do anything to get this same configuration as in device?
I had not /proc/config.gz so I can't get it easily.
Module source:
#include <linux/module.h>
#include <linux/kernel.h>
int __init example_init(void)
{
printk("Hello world!\n");
return 0;
}
void __exit example_exit(void)
{
printk("example module exit\n");
}
module_init(example_init);
module_exit(example_exit);
And I see Hello World! in dmesg but module is still permament.
Source of __gnu_mcount_nc i found here: http://doc.ironwoodlabs.com/arm-arm-none-eabi/html/getting-started/arm-mcount.html
Do you compile with with profile enable -pg flag when you build the kernel module? It looks that way.
The kernel module Makefile for CFLAGS.

Multi threading in borland

I'm programming c++ in Borland c++ 5.02. I'm trying to run this code:
#include <stdio.h>
#include <pthread.h>
#define NUM 5
main()
{
pthread_t t1, t2; /* two threads */
void *print_msg(void *);
pthread_create(&t1, NULL, print_msg, (void *)"hello");
pthread_create(&t2, NULL, print_msg, (void *)"world\n");
pthread_join(t1, NULL);
pthread_join(t2, NULL);
}
But I get this error:
Info :Compiling C:\BC5\BIN\noname00.cpp
Error: noname00.cpp(2,2):Unable to open include file 'PTHREAD.H'
Error: noname00.cpp(8,15):Undefined symbol 'pthread_t'
Error: noname00.cpp(8,15):Statement missing ;
Error: noname00.cpp(12,18):Call to undefined function 'pthread_create'
I highlighted the main error which is caused by 'PTHREAD.H'. I checked the include folder for this file. It doesn't exist. How can I fix this problem?
Borland's C++ toolchain doesn't include a pthreads library, nor does the Windows SDK. You'll either need to use native Win32 thread APIs or get a 3rd party pthreads implementation for Windows.
Some options include:
winpthreads.h: http://locklessinc.com/articles/pthreads_on_windows/
pthreads-win32: https://www.sourceware.org/pthreads-win32/
I have no idea how well those things work with Borland C++ 5.x.
Another alternative is to use a toolchain that includes a pthreads implementation, such as TDM's MinGW toolchain:
http://tdm-gcc.tdragon.net/
your problem is #include <pthread.h>
you need either copy all the pthread related files (.h,.c,.cpp,.hpp,.lib,.obj)
into compiler include folder
or add include path to it in your project/compiler settings
or copy it locally to your project and change #include <pthread.h> to #include "pthread.h"
So compiler did not find the pthread.h header
so no datatype from it is known from compiler side (like pthread_t)
therefore the rest of the errors...

Where is the declaration of CPU_ALLOC?

I'm using RHEL5 kernel 2.6.33 and running GCC v4.1.2.
During my program compilation, I get the warning "implicit declaration of function CPU_ALLOC" and the error "undefined reference to 'CPU_ALLOC'. I get the same warnings and errors for CPU_ZERO_S, CPU_SET_S, CPU_FREE, numa_bitmask_alloc, numa_bitmask_setbit and numa_bitmask_free.
I understand that CPU_ALLOC should be found in sched.h, but I've searched several sched.h (/usr/include/sched.h, /usr/include/bits/sched.h, /usr/include/linux/sched.h, /usr/src/kernels/linux-2.6.33.1/include/linux/sched.h), and cannot find CPU_ALLOC.
I have tried both #include <sched.h> and #include "/usr/include/sched.h", but I still have the errors.
I found declarations of CPU_ALLOC and the other functions on this website. Is this a file that I should have on my system?
How do I resolve this problem with the CPU_* and numa_bitmask_* functions?
Thank you.
Regards,
Rayne
You need to include the following in your header file containing CPU_ALLOC.
#define _GNU_SOURCE
#include <sched.h>

VS 10 includes, and I have a linker error

I am using Visual Studio 10 to program in C++
The 1st part of my program is
//Includes
//#include <LEDA\numbers> //fatal error C1083: Cannot open include file: 'LEDA\numbers': No such file or directory
#include <LEDA/numbers/real.h>
//Why do I get a linker error here
//All.obj : error LNK2001: unresolved external symbol "class leda::memory_manager leda::std_memory_mgr" (?std_memory_mgr#leda##3Vmemory_manager#1#A)
#include <LEDA\numbers\integer.h> //Here I used the system to write most of it for me
#include <LEDA/numbers/integer.h> //Include LEDA. So 2 things
//1. including the same file twice does not matter
//2. forward slashes and backward slashes are the same
//I tried to use a wild card and said #include <LEDA/numbers/*>
//But that did not work
#include <LEDA/numbers/rational.h>
#include <LEDA/core/string.h>
#include <LEDA/core/array.h>
#include <LEDA/numbers/bigfloat.h>
//The sqrt does not work
#include <iostream> //include ordinary C++
#include <math.h>
and I have a LINKER error
I have tried specifying which libraries to use by specifying the LIB User Environment symbol
I have tried specifying which libraries to use by specifying the
Include Directories and
Library Directories
in the properties of my Project
I have made a mistake somewhere, BUT where is it
There are several mistakes in this program:
LEDA\numbers is apparently a directory, not an include file. So you shouldn't try to include it.
(conceptual) #include statements don't help in resolving linker errors at all. Instead, you need to specify the libraries you want to link with to the linker; libraries are files that end in .lib. Go to the project settings, and add the libraries containing the missing symbols.
#include <abcd.h> // looks for the include abcd.h in the INCLUDES path.
#include "abcd.h" // looks for the include abcd.h in the current path and then INCLUDES path.
From your description it looks like your LEDA lib in under your current directory. Try using "" instead of <> and see if it fixes your errors.

Resources