- fixed a1.2 memory leaks and documented in a1.2.txt

This commit is contained in:
hamza 2025-05-08 21:44:13 +02:00
parent 46a6cd2c89
commit 141983790d
4 changed files with 22 additions and 1 deletions

View File

@ -3755,6 +3755,7 @@ CONFIG_NVMEM_SYSFS=y
# CONFIG_PECI is not set
# CONFIG_HTE is not set
CONFIG_SST=y
# CONFIG_SST_BOUNDS is not set
# CONFIG_SST_ASYNC_SOURCE is not set
# end of Device Drivers
@ -4444,7 +4445,7 @@ CONFIG_PTDUMP_CORE=y
# CONFIG_DEBUG_OBJECTS is not set
# CONFIG_SHRINKER_DEBUG is not set
CONFIG_HAVE_DEBUG_KMEMLEAK=y
# CONFIG_DEBUG_KMEMLEAK is not set
CONFIG_DEBUG_KMEMLEAK=y
# CONFIG_DEBUG_STACK_USAGE is not set
# CONFIG_SCHED_STACK_END_CHECK is not set
CONFIG_ARCH_HAS_DEBUG_VM_PGTABLE=y

9
a1.2.txt Normal file
View File

@ -0,0 +1,9 @@
1) a) um debug beim start des kerns zu aktivieren, reicht im Makefile die Debug output flags zu schalten: CFLAGS_sst_chrdev.o := -DDEBUG
CFLAGS_sst_common.o := -DDEBUG
CFLAGS_boundedbuffer.o := -DDEBUG
2) Mein grundlegendes Verständnis davon, wie kmemleak funktioniert, ist, dass jede neue Speicherzuweisung und ihre Zeiger zusammen mit einer Vielzahl von Metainformationen wie Größe verfolgt werden.
Informationen wie z.B. der Größe verfolgt und in einer Baumstruktur (rbtree) gespeichert wird.
einen Memory Allocator existiert, bedeutet dies, dass der Kernel nicht mehr in der Lage ist, ihn zu zerstören und er wird als Orphan bezeichnet.
3) um detector standardmäßige auszuschalten, kann mann CONFIG_DEBUG_KMEMLEAK=n setzen oder entfernen im kconfig

View File

@ -4,3 +4,6 @@
#
obj-$(CONFIG_SST) += sst_chrdev.o boundedbuffer.o sst_common.o
CFLAGS_sst_chrdev.o := -DDEBUG
CFLAGS_sst_common.o := -DDEBUG
CFLAGS_boundedbuffer.o := -DDEBUG

View File

@ -1,9 +1,12 @@
#include "sst_internal.h"
#include "../../include/linux/slab.h"
#include <linux/module.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/uaccess.h>
#include <linux/cdev.h>
#include <linux/slab.h>
#define SST_CHRDEV "the-universe"
@ -30,6 +33,7 @@ static ssize_t universe_read(struct file *file, char __user *buf, size_t count,
if (sst_consume_answer(sst_info, &answer)) {
pr_debug("Cannot read from answers!\n");
kfree(answer);
return 0;
}
len = strlen(answer);
@ -40,10 +44,12 @@ static ssize_t universe_read(struct file *file, char __user *buf, size_t count,
}
if (copy_to_user(buf, answer, min)) {
pr_err("User copy failed!\n");
kfree(answer);
return -EFAULT;
}
sst_debug("Copied %u bytes of your answer to the userspace: %s\n", min, answer);
*ppos += len;
kfree(answer);
return len;
}
@ -60,9 +66,11 @@ static ssize_t universe_write(struct file *file, const char __user *buf, size_t
err = sst_produce_question(sst_info, buf_copy);
if (err) {
pr_err("Weird! The universe is full.\n");
kfree(buf_copy);
return -ENOMEM;
}
sst_debug("Asked the universe a question...\n");
kfree(buf_copy);
return count;
}