valgrind

Segmentation fault- strcat

心不动则不痛 提交于 2020-01-13 14:09:38
问题 This is my code: #include<stdio.h> #include<stdlib.h> #include<string.h> void main(int arge, char *argv[]) { FILE *f1; char ch,*fn="~/lyrics/"; strcat(fn,argv[1]); strcat(fn,".txt"); if( (f1 = fopen(fn,"r"))==NULL ) { printf("\nWrong filename\n%s not found",argv[1]); return; } while((ch=getw(f1))!=EOF) { printf("%c",ch); } } I compiled it using gcc -g -o file file.c and the compiler gave no error messages. But when I run it I get the error message: Segmentation fault (core dumped) Bad

Segmentation fault- strcat

这一生的挚爱 提交于 2020-01-13 14:09:09
问题 This is my code: #include<stdio.h> #include<stdlib.h> #include<string.h> void main(int arge, char *argv[]) { FILE *f1; char ch,*fn="~/lyrics/"; strcat(fn,argv[1]); strcat(fn,".txt"); if( (f1 = fopen(fn,"r"))==NULL ) { printf("\nWrong filename\n%s not found",argv[1]); return; } while((ch=getw(f1))!=EOF) { printf("%c",ch); } } I compiled it using gcc -g -o file file.c and the compiler gave no error messages. But when I run it I get the error message: Segmentation fault (core dumped) Bad

Segmentation fault- strcat

只谈情不闲聊 提交于 2020-01-13 14:08:01
问题 This is my code: #include<stdio.h> #include<stdlib.h> #include<string.h> void main(int arge, char *argv[]) { FILE *f1; char ch,*fn="~/lyrics/"; strcat(fn,argv[1]); strcat(fn,".txt"); if( (f1 = fopen(fn,"r"))==NULL ) { printf("\nWrong filename\n%s not found",argv[1]); return; } while((ch=getw(f1))!=EOF) { printf("%c",ch); } } I compiled it using gcc -g -o file file.c and the compiler gave no error messages. But when I run it I get the error message: Segmentation fault (core dumped) Bad

How do I make ctest run a program with valgrind without dart?

不问归期 提交于 2020-01-11 15:46:06
问题 I want to write a CMakeLists.txt so that I can run my tests normally or with valgrind. I have seen much on integrating ctest with valgrind but all with the assumption that you want to set up a server to submit test results to a dart dashboard. I just want to run the tests on my machine and see the results on the command line. If I have to do a cmake -D VALGRIND=ON thats fine, but I'd rather generate tests named "foo" and "valgrind_foo" if possible. 回答1: I use valgrind for my memory check. To

Why would this give a Use of uninitialised value of size 8

杀马特。学长 韩版系。学妹 提交于 2020-01-11 05:05:51
问题 In my code I have a class named membrane with a function named exciteMod() , a function named decide() and a variable named delta_U . The first line of exciteMod() is this->delta_U = 0 . In decide() I have an exponent of -delta_U ( exp(-this->delta_U) ). which cause an error Use of uninitialised value of size 8. What might cause this? I don't have any error about delta_U which is generated in valgrind. Edit: Here are the relevant segment of the code: void membrane::exciteMod(){ this->delta_U

Why would this give a Use of uninitialised value of size 8

泄露秘密 提交于 2020-01-11 05:05:47
问题 In my code I have a class named membrane with a function named exciteMod() , a function named decide() and a variable named delta_U . The first line of exciteMod() is this->delta_U = 0 . In decide() I have an exponent of -delta_U ( exp(-this->delta_U) ). which cause an error Use of uninitialised value of size 8. What might cause this? I don't have any error about delta_U which is generated in valgrind. Edit: Here are the relevant segment of the code: void membrane::exciteMod(){ this->delta_U

Why does malloc allocate more memory spaces than I ask for? [duplicate]

一笑奈何 提交于 2020-01-11 04:06:05
问题 This question already has answers here : Malloc vs custom allocator: Malloc has a lot of overhead. Why? (3 answers) Closed 3 years ago . I found that malloc() allocates more memory spaces than I ask for. struct { void *ptr; int var; } msg; // 16 bytes (checked by sizeof()) for (int i = 0; i < 100000000; i++) malloc(sizeof(msg)); As the aforementioned code, malloc() actually allocate 32 bytes per function call (calculated by top ), but valgrind shows only 16 bytes per call indeed. Why does

valgrind mac os mem leak

北慕城南 提交于 2020-01-09 19:55:11
问题 Today I installed valgrind on my Mac os x 10.6 and tried to test it out. And it turned out to be weird memory leaks in the system. What I did was just create simple c file that get some heap memory and immediately free it. When I ran valgrind it showed something like this Realfrees-MacBook-Pro:C Realfree$ valgrind --tool=memcheck --leak-check=yes --show-reachable=yes ./a.out ==2621== Memcheck, a memory error detector ==2621== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al. =

Valgrind reports memory leak when assigning a value to a string

谁说我不能喝 提交于 2020-01-09 10:42:45
问题 Valgrind reports a memory leak when assigning a value to a string. I used the following simple code to test an memory leak reported by Valgrind. /****************************************** * FILE: t3.c * Compiled using : g++ -g t3.c -o t3 * * $ g++ -v * Reading specs from /usr/lib/gcc/i686-pc-linux-gnu/3.4.6/specs * Configured with: ./configure --prefix=/usr --infodir=/share/info --mandir=/share/man * --enable-languages=c,c++ --with-system-zlib --program-suffix=-3.4 --enable-threads=posix *

Data race during nested thread creation

試著忘記壹切 提交于 2020-01-07 02:49:09
问题 While trying to create nested threads, helgrind reports several different types of data races. ==4429== Possible data race during write of size 8 at 0x5673830 by thread #13 ==4429== Locks held: none ==4429== at 0x4C379EF: memset (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so) ==4429== by 0x5060C85: get_cached_stack (allocatestack.c:250) ==4429== by 0x5060C85: allocate_stack (allocatestack.c:501) ==4429== by 0x5060C85: pthread_create@@GLIBC_2.2.5 (pthread_create.c:537) ==4429== by