Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

corrupted double-linked list po użyciu fclose();

Ostatnio zmodyfikowano 2016-01-04 11:17
Autor Wiadomość
daniel1302
Temat założony przez niniejszego użytkownika
corrupted double-linked list po użyciu fclose();
» 2016-01-01 19:05:20
Witam, napisałem funkcję która wykorzystuje funkcje fclose(); Po użyciu tej funkcji dostaję błąd:
*** Error in `./server': corrupted double-linked list: 0x000000000251a230 ***
Przerwane (zrzut pamięci)

Po usunięciu funkcji błąd znika.

FILE *fHandler;
struct udp_message **returnArray;
struct udp_message *message;
char *line = NULL;
uint32_t linesNum;
uint32_t i = 0;
size_t length;
ssize_t read;

fHandler = fopen(filePath, "r");
if (fHandler == NULL) {
    perror("ERROR");
    return NULL;
}

returnArray = malloc(sizeof(struct udp_message *)*CONSOLE_BUFFER);
message = malloc(sizeof(struct udp_message));

while ((read = getline(&line, &length, fHandler)) != -1) {
    message = (struct udp_message *)line;
    if (message->messageTime < aboveTime) {
        continue;
    }

    returnArray[i] = malloc(sizeof(struct udp_message));
    memcpy(returnArray[i++], message, sizeof(struct udp_message));
}

memcpy(messageNum, &i, sizeof(i));
fclose(fHandler);

return returnArray;
P-142664
DejaVu
» 2016-01-04 11:17:34
getline odczytuje dane do niezaalokowanego obszaru pamieci.

/edit:
If *lineptr is set to NULL and *n is set 0 before the call, then
       getline() will allocate a buffer for storing the line.  This buffer
       should be freed by the user program even if getline() failed.
P-142833
« 1 »
  Strona 1 z 1