From d1d33d9d3eb55edbb8d3dd2e46f1b57ecb0e4f5c Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Sun, 31 May 2020 18:34:38 +0100 Subject: [PATCH] Fixing memory errors --- mcplayerstat.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mcplayerstat.c b/mcplayerstat.c index 1b41070..2f02ff2 100644 --- a/mcplayerstat.c +++ b/mcplayerstat.c @@ -13,12 +13,14 @@ void printInventory(TagList *inv) { if(!strncmp(attr.name,"Slot",attr.nameLength)) { slot = *((uint8_t*)attr.payload); } else if(!strncmp(attr.name,"id",attr.nameLength)) { - id = (char*)attr.payload; + id = calloc(attr.payloadLength+1,sizeof(char)); + memcpy(id,(char*)attr.payload,attr.payloadLength); } else if(!strncmp(attr.name,"Count",attr.nameLength)) { count = *((uint8_t*)attr.payload); } } printf("\t- [%u] %ux %s\n",slot,count,id); + free(id); } } -- libgit2 0.22.2