请问这个代码哪里错了,编译成功且没有报警但运行出错


#1
#define DEBUG
#include <iostream>
#include <string>
using std::string;
using std::cout;
using std::cin;
using std::endl;


int main(){
	char *psome = new char[30];
#ifdef DEBUG
	cout<<1<<endl;
#endif
	psome=(char*)"hello,world!\n";
#ifdef DEBUG
	cout<<2<<endl;
#endif
	delete []psome;
#ifdef DEBUG
	cout<<3<<endl;
#endif
	return 0;
}
文字缩进 4 格

运行如下 1 2 *** Error in `./main’: free(): invalid pointer: 0x0000000000400961 *** ======= Backtrace: ========= /lib64/libc.so.6(+0x7c8dc)[0x7f33062d78dc] /lib64/libc.so.6(+0x87789)[0x7f33062e2789] /lib64/libc.so.6(cfree+0x16e)[0x7f33062e80ee] ./main[0x400850] /lib64/libc.so.6(__libc_start_main+0xea)[0x7f330627b50a] ./main[0x40073a] ======= Memory map: ======== 00400000-00401000 r-xp 00000000 08:03 26746155 /home/cfg/main 00600000-00601000 r–p 00000000 08:03 26746155 /home/cfg/main 00601000-00602000 rw-p 00001000 08:03 26746155 /home/cfg/main 0200d000-0203f000 rw-p 00000000 00:00 0 [heap] 7f3300000000-7f3300021000 rw-p 00000000 00:00 0 7f3300021000-7f3304000000 —p 00000000 00:00 0 7f330625b000-7f3306422000 r-xp 00000000 08:01 1059570 /usr/lib64/libc-2.25.so 7f3306422000-7f3306622000 —p 001c7000 08:01 1059570 /usr/lib64/libc-2.25.so 7f3306622000-7f3306626000 r–p 001c7000 08:01 1059570 /usr/lib64/libc-2.25.so 7f3306626000-7f3306628000 rw-p 001cb000 08:01 1059570 /usr/lib64/libc-2.25.so 7f3306628000-7f330662c000 rw-p 00000000 00:00 0 7f330662c000-7f3306642000 r-xp 00000000 08:01 1059632 /usr/lib64/libgcc_s-7-20170915.so.1 7f3306642000-7f3306841000 —p 00016000 08:01 1059632 /usr/lib64/libgcc_s-7-20170915.so.1 7f3306841000-7f3306842000 r–p 00015000 08:01 1059632 /usr/lib64/libgcc_s-7-20170915.so.1 7f3306842000-7f3306843000 rw-p 00016000 08:01 1059632 /usr/lib64/libgcc_s-7-20170915.so.1 7f3306843000-7f3306958000 r-xp 00000000 08:01 1059755 /usr/lib64/libm-2.25.so 7f3306958000-7f3306b57000 —p 00115000 08:01 1059755 /usr/lib64/libm-2.25.so 7f3306b57000-7f3306b58000 r–p 00114000 08:01 1059755 /usr/lib64/libm-2.25.so 7f3306b58000-7f3306b59000 rw-p 00115000 08:01 1059755 /usr/lib64/libm-2.25.so 7f3306b59000-7f3306cd3000 r-xp 00000000 08:01 1060411 /usr/lib64/libstdc++.so.6.0.24 7f3306cd3000-7f3306ed3000 —p 0017a000 08:01 1060411 /usr/lib64/libstdc++.so.6.0.24 7f3306ed3000-7f3306edd000 r–p 0017a000 08:01 1060411 /usr/lib64/libstdc++.so.6.0.24 7f3306edd000-7f3306edf000 rw-p 00184000 08:01 1060411 /usr/lib64/libstdc++.so.6.0.24 7f3306edf000-7f3306ee2000 rw-p 00000000 00:00 0 7f3306ee2000-7f3306f09000 r-xp 00000000 08:01 1062960 /usr/lib64/ld-2.25.so 7f33070e2000-7f33070e6000 rw-p 00000000 00:00 0 7f3307105000-7f3307108000 rw-p 00000000 00:00 0 7f3307108000-7f3307109000 r–p 00026000 08:01 1062960 /usr/lib64/ld-2.25.so 7f3307109000-7f330710b000 rw-p 00027000 08:01 1062960 /usr/lib64/ld-2.25.so 7ffde721d000-7ffde723f000 rw-p 00000000 00:00 0 [stack] 7ffde73ed000-7ffde73f0000 r–p 00000000 00:00 0 [vvar] 7ffde73f0000-7ffde73f2000 r-xp 00000000 00:00 0 [vdso] ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,objc,obj-c++,fortran,ada,go,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 7.2.1 20170915 (Red Hat 7.2.1-2) (GCC) 

thx


#2

貌似编译器bug…


#3
int main(){
	char *psome = new char[30];     // < psome指向堆中内存
#ifdef DEBUG
	cout<<1<<endl;
#endif
	psome=(char*)"hello,world!\n";  // < psome指向常量区内存
#ifdef DEBUG
	cout<<2<<endl;
#endif
	delete []psome;                 // < 试图释放常量区数据,肯定挂啊。。。。
#ifdef DEBUG
	cout<<3<<endl;
#endif
	return 0;
}