valgrind

Valgrind Error when creating an array of linked lists (for Hash Table Chaining)

回眸只為那壹抹淺笑 提交于 2020-01-17 06:17:08
问题 As an overview, I'm trying to create a battleship-like game in C, where ships are placed on a field. Here is the error I am getting: ==11147== Invalid write of size 8 ==11147== at 0x400786: MakeField (battleship.c:34) ==11147== Address 0x8 is not stack'd, malloc'd or (recently) free'd Here is the relevant code: struct piece{ int x; int y; int direction; int length; char name; }; struct node{ struct piece boat; struct node *next; }; struct field{ int numBoats; struct node *array[numRows]; };

How to properly malloc item in struct array hashmap in C

こ雲淡風輕ζ 提交于 2020-01-16 09:11:30
问题 In the following code, I'm using malloc for adding a new item to a hashmap. I thought I've checked all the boxes for properly using malloc, but valgrind says I've got a memory leak on them. Can someone point me to where I've gone wrong? #include <stdlib.h> #include <string.h> typedef struct node { char content[46]; struct node* next; } node; typedef node* hashmap_t; int main (int argc, char *argv[]) { hashmap_t hashtable[1000]; node *n = malloc(sizeof(node)); if(n == NULL) return 0; hashmap_t

valgrind 编译海思

感情迁移 提交于 2020-01-15 19:07:41
https://blog.csdn.net/understand125/article/details/80689564 https://blog.csdn.net/fengbingchun/article/details/97756419 创建一个脚本build.sh, 内容如下: ./configure --host=arm-hisiv100nptl-linux --prefix=/`pwd`/valgrind CC=arm-hisiv100nptl-linux-gcc CPP=arm-hisiv100nptl-linux-cpp AR=arm-hisiv100nptl-linux-ar 检测命令 ./valgrind --tool=memcheck --leak-check=full ./main 来源: CSDN 作者: ren1204 链接: https://blog.csdn.net/ren1204/article/details/103989773

Eclipse Luna error messages on GDB and Valgrind, unable to Debug or Profile C++ program as Local C/C++ Application

时光总嘲笑我的痴心妄想 提交于 2020-01-15 11:16:08
问题 I downloaded Eclipse Luna for 64-bit Mac OS X just a few days ago. Would like to use Eclipse for a small C++ program assigned as student homework. Set this up as an Eclipse C++ project. I built the selected configuration as Debug and run it as Local C/C++ Application. All good. My C++ program runs and output appears in Console window exactly as I want it. When I attempt Debug as Local C/C++ Application there is a message window Error with command: gdb --version. Cannot run program 'gdb':

Getting data from pointer in struct “Invalid read/write”

偶尔善良 提交于 2020-01-15 10:03:56
问题 I am trying to do a implementation of circular buffer in array. I keep my data in structure and manage it by few methods as push, pop, etc. The program is more or less functional and behave as expected, however I run into errors in my valgrind test. And I am not capable of finding out what is wrong with my code. Although it seems like managing data via pointers in my struct is the crucial problem. I would be very grateful if anyone could point me in the right direction coz I am really lost at

KCachegrind output for optimized vs unoptimized builds

自古美人都是妖i 提交于 2020-01-15 09:55:48
问题 I run valgrind --tool=callgrind ./executable on the executable file generated by the following code: #include <cstdlib> #include <stdio.h> using namespace std; class XYZ{ public: int Count() const {return count;} void Count(int val){count = val;} private: int count; }; int main() { XYZ xyz; xyz.Count(10000); int sum = 0; for(int i = 0; i < xyz.Count(); i++){ //My interest is to see how the compiler optimizes the xyz.Count() call sum += i; } printf("Sum is %d\n", sum); return 0; } I make a

valgrind Error: Conditional jump or move depends on uninitialised value(s)

╄→гoц情女王★ 提交于 2020-01-14 10:43:14
问题 I have one program: #include <stdio.h> int call(){ int x=25; ++x; return x; } int main(){ int p; p=call(); printf("%d",p); return 0; } When I compile the program with -g option and run it with valgrind it shows: ==15469== 1 errors in context 1 of 8: ==15469== Conditional jump or move depends on uninitialised value(s) ==15469== at 0x546F83: _dl_relocate_object (in /lib/ld-2.12.90.so) ==15469== by 0x53E6CC: dl_main (in /lib/ld-2.12.90.so) ==15469== by 0x55094D: _dl_sysdep_start (in /lib/ld-2.12

valgrind stalls in multithreaded socket program

戏子无情 提交于 2020-01-14 10:05:02
问题 I'm running a multithreaded socket program with valgrind. The client will send out a request to the server over TCP, and then busy wait on a boolean. The boolean will be set when the callback function which services the response from the server is called. Once the response is received (and the boolean flag is set), the server will again send out a request, and do this repeatedly in a loop. I realise that unsychronised access to shared variables (the boolean) can cause threading issues, but I

Restricting Valgrind to a specific function

送分小仙女□ 提交于 2020-01-14 07:40:09
问题 I have a big program to run. Using valgrind it takes hours and hours to run. I heard that there is something where we can call valgrind for a specific function in the program. And rest of program will be executed normally(without valgrind env). Can anybody help me with this. I tried searching it over internet , May be I am missing the term to search. 回答1: It all depends on what tool you're wanting to use. For callgrind (the profiler in valgrind) there is an option --toggle-collect=function to

Segmentation fault- strcat

牧云@^-^@ 提交于 2020-01-13 14:12:12
问题 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