Skip to content

This Repository is a collection of different ethical hacking tools and malware's for penetration testing and research purpose written in python, ruby, rust, c++, go and c.

Create program to avoid memory leaks.c

Abdul Wahab Junaid8d5172aaf22f
diff --git a/C Hacking Tools/program to avoid memory leaks.c b/C Hacking Tools/program to avoid memory leaks.c
new file mode 100644
index 0000000..19c6b5c
--- /dev/null
+++ b/C Hacking Tools/program to avoid memory leaks.c
@@ -0,0 +1,34 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(int argc, char *argv[]) {
+ char *input = malloc(20);
+ char *output = malloc(20);
+
+ if (input == NULL || output == NULL) {
+ fprintf(stderr, "Memory allocation failed\n");
+ return 1;
+ }
+
+ strncpy(output, "normal output", 20);
+ output[19] = '\0'; // Ensure null termination
+
+ if (argc > 1) {
+ strncpy(input, argv[1], 19); // Copy at most 19 characters
+ input[19] = '\0'; // Ensure null termination
+ } else {
+ fprintf(stderr, "No input provided\n");
+ return 1;
+ }
+
+ printf("input at %p: %s\n", (void *)input, input);
+ printf("output at %p: %s\n", (void *)output, output);
+ printf("\n\n%s\n", output);
+
+ // Free allocated memory before exiting
+ free(input);
+ free(output);
+
+ return 0;
+}