关于linux下编译动态链接库调用有关问题

关于linux下编译动态链接库调用问题
大侠们,我在linux下用g++编译带有STL的动态链接库,当我调用该库的函数执行完后,会报STL分配空错误,请大侠帮忙看看。代码如下:
动态库头文件:
testlib.h
#include <vector>
using namespace std;
typedef struct 

int left; 
int right;
int top;
int bottom;
}KeyRect;

vector <KeyRect> tt;
 int printvector();

动态库cpp文件:
testlib.cpp
#include "testlib.h"
#include <stdio.h>
int printvector()
{
     KeyRect rct;
     for(int i=0;i<5;i++)
     {
rct.left = i;
rct.right =i+1;
rct.top = i+2;
rct.bottom = i+3;
tt.push_back(rct);
     }

     for(int j=0;j<tt.size();j++)
     {
printf("the %dth elment in vector is %d %d %d %d\n",tt[j].left,tt[j].right,tt[j].top,tt[j].bottom);

     }
    return 0;
}

用g++  -fPIC -shared -g -o  libtest.so  testlib.cpp  命令编译生成libtest.so库,
测试用例cpp如下:
test.cpp
#include <stdio.h>
#include "testlib.h"

int main()
{
int result =0;
printvector();
return 0;
}
用g++ test.cpp  ./libyang.so -g  -o test    生成可移植文件test

用./test命令执行,打印如下:

the 0th elment in vector is 0,1,2,3                                                           
the 1th elment in vector is 1,2,3,4
the 2th elment in vector is 2,3,4,5
the 3th elment in vector is 3,4,5,6
the 4th elment in vector is 4,5,6,7
(注:以上五行打印为动态库中函数输出,正确,下面为异常打印)
*** glibc detected *** ./test: double free or corruption (out): 0x0940f090 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6(+0x6b591)[0x65c591]
/lib/tls/i686/cmov/libc.so.6(+0x6cde8)[0x65dde8]
/lib/tls/i686/cmov/libc.so.6(cfree+0x6d)[0x660ecd]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0x567741]
./test(_ZN9__gnu_cxx13new_allocatorI7KeyRectE10deallocateEPS1_j+0x11)[0x8048d8f]
./test(_ZNSt12_Vector_baseI7KeyRectSaIS0_EE13_M_deallocateEPS0_j+0x25)[0x8048d61]
./test(_ZNSt12_Vector_baseI7KeyRectSaIS0_EED2Ev+0x38)[0x8048cca]
./test(_ZNSt6vectorI7KeyRectSaIS0_EED1Ev+0x39)[0x8048dd1]
/lib/tls/i686/cmov/libc.so.6(__cxa_finalize+0xb8)[0x620588]
./libtestlib.so(+0x1d04)[0x2a3d04]
./libtestlib.so(+0x2b80)[0x2a4b80]
/lib/ld-linux.so.2(+0xe2a6)[0x96e2a6]
/lib/tls/i686/cmov/libc.so.6(+0x2f1bf)[0x6201bf]
/lib/tls/i686/cmov/libc.so.6(+0x2f22f)[0x62022f]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xee)[0x607bde]
./test[0x8048b31]
======= Memory map: ========
002a2000-002a6000 r-xp 00000000 08:01 936760     /home/fy/code/ImageDll/libtestlib.so
002a6000-002a7000 r--p 00003000 08:01 936760     /home/fy/code/ImageDll/libtestlib.so
002a7000-002a8000 rw-p 00004000 08:01 936760     /home/fy/code/ImageDll/libtestlib.so
004ac000-00595000 r-xp 00000000 08:01 807509     /usr/lib/libstdc++.so.6.0.13
00595000-00599000 r--p 000e9000 08:01 807509     /usr/lib/libstdc++.so.6.0.13
00599000-0059a000 rw-p 000ed000 08:01 807509     /usr/lib/libstdc++.so.6.0.13
0059a000-005a1000 rw-p 00000000 00:00 0 
005f1000-00744000 r-xp 00000000 08:01 264023     /lib/tls/i686/cmov/libc-2.11.1.so
00744000-00745000 ---p 00153000 08:01 264023     /lib/tls/i686/cmov/libc-2.11.1.so
00745000-00747000 r--p 00153000 08:01 264023     /lib/tls/i686/cmov/libc-2.11.1.so
00747000-00748000 rw-p 00155000 08:01 264023     /lib/tls/i686/cmov/libc-2.11.1.so
00748000-0074b000 rw-p 00000000 00:00 0 
008a8000-008cc000 r-xp 00000000 08:01 264031     /lib/tls/i686/cmov/libm-2.11.1.so
008cc000-008cd000 r--p 00023000 08:01 264031     /lib/tls/i686/cmov/libm-2.11.1.so
008cd000-008ce000 rw-p 00024000 08:01 264031     /lib/tls/i686/cmov/libm-2.11.1.so
00960000-0097b000 r-xp 00000000 08:01 133390     /lib/ld-2.11.1.so
0097b000-0097c000 r--p 0001a000 08:01 133390     /lib/ld-2.11.1.so
0097c000-0097d000 rw-p 0001b000 08:01 133390     /lib/ld-2.11.1.so
00a6f000-00a8c000 r-xp 00000000 08:01 136632     /lib/libgcc_s.so.1
00a8c000-00a8d000 r--p 0001c000 08:01 136632     /lib/libgcc_s.so.1