class - Segmentation Fault Accessing Singleton C++ -


overview

i writing helper class make calls redis easier xredis drivers in c++, continually receiving segmentation fault upon requesting or sending information instance.

i think has way i'm storing xredis , redisdbidx instances, , possibly way i'm storing redisadmin instance within main application, i'm unable see right way set these after several attempts.

relevant code below, , few notes on debugging steps have taken myself.

debugging notes

  • redis server started successfully, , log output shows successful connection server on instance startup
  • the call fails whether set or exists command sent server
  • gdb output shows below, , logs show same happenning on either exists or set calls:

    program received signal sigsegv, segmentation fault. redispool::getconnection (this=0x0, cahcetype=0, dbindex=0, iotype=0) @ src/xredispool.cpp:124 124        || (iotype>slave) 

code

redis_admin.h

#include "xredis/xredisclient.h" #include <string.h> #include <string>  class xredisadmin { xredisclient xred; public:     xredisadmin(redisnode conn_list[], int conn_list_size);     ~xredisadmin();     const char * load ( const char * key );     bool save ( const char * key, const char * msg );     bool exists ( const char * key );     bool del ( const char * key ); }; 

redis_admin.cpp

xredisadmin::xredisadmin(redisnode conn_list[], int conn_list_size) { enum { cache_type_1, cache_type_2, cache_type_max, };  xred.init(cache_type_max); bool bret = xred.connectrediscache(conn_list, conn_list_size, cache_type_1); //log results }  //exists bool xredisadmin::exists(const char * key) { redisdbidx d(&xredis); char szkey[256] = {0}; sprintf(szkey, key); return xred.exists(d, szkey); }  //save bool xredisadmin::save(const char * key, const char * val) { redisdbidx d(&xred); char szkey[256] = {0}; sprintf(szkey, key); bool ret_val = xred.set(d, szkey, val); //log output return ret_val; } 

main.cpp

xredisadmin *xred;  void example_callback() {     bool bret = xred->save("key", "c_str"); }  int main() {     xredisadmin x (redislist1, conn_list_size);     xred = &x;      example_callback();     return 0; } 

as turns out, violating rule of threes.

i did not have copy constructor redis admin, , xred object inside became null on assignment because of this. use of new & delete, rather creating in main method, did resolve issue. proved solution issue

thanks commented , gave me answers & support!

alex


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -