0
C 및 libconfig를 사용하여 구성 파일에서 사용자 값을 검색 할 수 없습니다.libconfig로 config를 읽을 때 SIGSEGV
configreader.h
#include <stdio.h>
#include <string.h>
#include <libconfig.h>
#ifndef CONFIGREADER_H_INCLUDED
#define CONFIGREADER_H_INCLUDED
char *userreader(){
static const char *inputfile = "/opt/plaininc/config/handler.conf";
config_t configreader;
const char *userconfig;
if(! config_read_file(&configreader, inputfile)){
config_destroy(&configreader);
exit(EXIT_FAILURE);
}
if (config_lookup_string(&configreader, "handler.user", &userconfig)){
config_destroy(&configreader);
return userconfig;
} else {
config_destroy(&configreader);
exit(EXIT_FAILURE);
}
}
#endif
CONFIG.c
#include <stdio.h>
#include <stdlib.h>
#include "configreader.h"
int main(){
const char *user = userreader();
printf("%s", user);
}
GDB :
프로그램 신호 SIGSEGV 세그멘테이션 결함을 받았다. 무료()에서 0xb7e63496
'config_destroy'의 기능은 무엇입니까? – tkausl
헤더 파일에 함수가있는 이유는 무엇입니까? 그리고 오류를 재현하는 데 필요한 모든 코드를 포함하시기 바랍니다. – Unh0lys0da
@tkausl config_destroy()는 구성 설정을 삭제하고 구성과 관련된 모든 메모리를 할당 해제하지만 config_t 구조 자체를 할당 해제하지는 않습니다. –