free

which free tools can I use to generate the program dependence graph for c codes

混江龙づ霸主 提交于 2019-12-03 07:04:33
问题 I want to generate a Program Dependence Graph (PDG) from C source code. I found papers that explain how do it, but all used the commercial CodeSurfer tool. Are there any free tools or open source projects that can do this job? 回答1: Frama-C is an Open Source static analysis platform with a slicer for C programs based on the computation of a Program Dependence Graph. Note that slicing actual programs written in a real programming language such as C involves many special cases and concepts that

Free memory allocated in a different function?

China☆狼群 提交于 2019-12-03 06:26:28
问题 I'm trying to learn C and I'm currently trying to write a basic stack data structure, but I can't seem to get basic malloc / free right. Here's the code I've been using (I'm just posting a small part here to illustrate a specific problem, not the total code, but the error message was generated just by running this example code in valgrind ) #include <stdio.h> #include <stdlib.h> typedef struct Entry { struct Entry *previous; int value; } Entry; void destroyEntry(Entry entry); int main(int

Freeing memory twice

只愿长相守 提交于 2019-12-03 04:52:34
问题 In C and C++, Freeing a NULL pointer will result in nothing done. Still, I see people saying that memory corruption can occur if you "free memory twice". Is this true? What is going on under the hood when you free memory twice? 回答1: int *p = malloc(sizeof(int)); //value of p is now lets say 0x12345678 *p = 2; free(p); //memory pointer is freed, but still value of p is 0x12345678 //now, if you free again, you get a crash or undefined behavior. So, after free ing the first time, you should do p

Freeing strings in C

浪尽此生 提交于 2019-12-03 04:04:06
If I would write: char *a=malloc(sizeof(char)*4); a="abc"; char *b="abc"; do I need to free this memory, or is it done by my system? In your situation you won't have any way to free the dynamic allocated memory because you are losing the reference to it. Try this out: #include <stdio.h> #include <stdlib.h> int main() { char *a=(char*)malloc(sizeof(char)*4); printf("Before: %p\n",a); a = "abc"; printf("After: %p\n",a); free(a); char *b = "abc"; return 0; } You will obtain Before: 0x100100080 After: 0x100000f50 You will see that the two pointers are different. This because the string literal

When do I need dynamic memory? [duplicate]

喜你入骨 提交于 2019-12-02 23:56:36
Possible Duplicate: Malloc or normal array definition? We learn that there is dynamic memory in C and dynamic variables: #include <stdio.h> int a = 17; int main(void) { int b = 18; //automatic stack memory int * c; c = malloc( sizeof( int ) ); //dynamic heap memory *c = 19; printf("a = %d at address %x\n", a, &a); printf("b = %d at address %x\n", b, &b); printf("c = %d at address %x\n", *c, c); free(c); system("PAUSE"); return 0; } How do I know which type of memory to use? When do I ned one or the other? Use dynamic in the following situations: When you need a lot of memory. Typical stack

GlibC Double free or corruption (fclose)

二次信任 提交于 2019-12-02 21:46:10
问题 I got an error on my C program on runtime. I found some stuff about "double free or corruption" error but nothing relevant. Here is my code : void compute_crc32(const char* filename, unsigned long * destination) { FILE* tmp_chunk = fopen(filename, "rb"); printf("\n\t\t\tCalculating CRC..."); fflush(stdout); Crc32_ComputeFile(tmp_chunk, destination); printf("\t[0x%08lX]", *destination); fflush(stdout); fclose(tmp_chunk); printf("\t[ OK ]"); fflush(stdout); } It seems the fclose(tmp_chunk);

Free memory allocated in a different function?

两盒软妹~` 提交于 2019-12-02 19:54:28
I'm trying to learn C and I'm currently trying to write a basic stack data structure, but I can't seem to get basic malloc / free right. Here's the code I've been using (I'm just posting a small part here to illustrate a specific problem, not the total code, but the error message was generated just by running this example code in valgrind ) #include <stdio.h> #include <stdlib.h> typedef struct Entry { struct Entry *previous; int value; } Entry; void destroyEntry(Entry entry); int main(int argc, char *argv[]) { Entry* apple; apple = malloc(sizeof(Entry)); destroyEntry(*(apple)); return 0; }

which free tools can I use to generate the program dependence graph for c codes

社会主义新天地 提交于 2019-12-02 19:37:35
I want to generate a Program Dependence Graph (PDG) from C source code. I found papers that explain how do it, but all used the commercial CodeSurfer tool. Are there any free tools or open source projects that can do this job? Pascal Cuoq Frama-C is an Open Source static analysis platform with a slicer for C programs based on the computation of a Program Dependence Graph. Note that slicing actual programs written in a real programming language such as C involves many special cases and concepts that are skimmed over in scientific publications. Still, I am confident that you won't find anything

Freeing memory twice

随声附和 提交于 2019-12-02 19:03:33
In C and C++, Freeing a NULL pointer will result in nothing done. Still, I see people saying that memory corruption can occur if you "free memory twice". Is this true? What is going on under the hood when you free memory twice? N 1.1 int *p = malloc(sizeof(int)); //value of p is now lets say 0x12345678 *p = 2; free(p); //memory pointer is freed, but still value of p is 0x12345678 //now, if you free again, you get a crash or undefined behavior. So, after free ing the first time, you should do p = NULL , so if (by any chance), free(p) is called again, nothing will happen. Here is why freeing

No warnings when trying to access freed memory in C [duplicate]

我只是一个虾纸丫 提交于 2019-12-02 17:28:45
问题 This question already has answers here : Why do I get different results when I dereference a pointer after freeing it? (7 answers) Closed 5 years ago . I'm trying to understand the how the memory is managed in C. In the sample code below, in the comments I have added my understanding on how the memory is managed. I would like to know if I'm correct In the final part of the code, I'm trying to access a part of memory which is already freed. I'm surprised why the compiler did not through any