Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

seg-fault in v1.8 release #294

Closed
chenziliang opened this issue Jun 19, 2019 · 10 comments
Closed

seg-fault in v1.8 release #294

chenziliang opened this issue Jun 19, 2019 · 10 comments

Comments

@chenziliang
Copy link

chenziliang commented Jun 19, 2019

Tried using v1.8 release (the single CLI11.hpp file) in my project, got seg-fault, the following is the trace.

(gdb) bt
#0  __GI___libc_free (mem=0x93fa55d09a576) at malloc.c:3103
#1  0x000055555565846e in __gnu_cxx::new_allocator<CLI::App*>::deallocate (this=0x5555569ec7a0, __p=0x93fa55d09a576) at /usr/include/c++/8/ext/new_allocator.h:125
#2  0x000055555564efe5 in std::allocator_traits<std::allocator<CLI::App*> >::deallocate (__a=..., __p=0x93fa55d09a576, __n=18446418666927868753)
    at /usr/include/c++/8/bits/alloc_traits.h:462
#3  0x00005555556430fe in std::_Vector_base<CLI::App*, std::allocator<CLI::App*> >::_M_deallocate (this=0x5555569ec7a0, __p=0x93fa55d09a576, __n=18446418666927868753)
    at /usr/include/c++/8/bits/stl_vector.h:304
#4  0x0000555555633170 in std::_Vector_base<CLI::App*, std::allocator<CLI::App*> >::~_Vector_base (this=0x5555569ec7a0, __in_chrg=<optimized out>)
    at /usr/include/c++/8/bits/stl_vector.h:285
#5  0x0000555555621653 in std::vector<CLI::App*, std::allocator<CLI::App*> >::~vector (this=0x5555569ec7a0, __in_chrg=<optimized out>)
    at /usr/include/c++/8/bits/stl_vector.h:570
#6  0x00005555556114aa in CLI::App::~App (this=0x5555569ec640, __in_chrg=<optimized out>) at /.../CLI11.hpp:3912
#7  0x0000555555611584 in CLI::App::~App (this=0x5555569ec640, __in_chrg=<optimized out>) at /.../CLI11.hpp:3912
#8  0x0000555555678944 in std::_Sp_counted_ptr<CLI::App*, (__gnu_cxx::_Lock_policy)2>::_M_dispose (this=0x5555569f3130) at /usr/include/c++/8/bits/shared_ptr_base.h:377
#9  0x00005555556298b2 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release (this=0x5555569f3130) at /usr/include/c++/8/bits/shared_ptr_base.h:155
#10 0x0000555555618061 in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count (this=0x5555569f2678, __in_chrg=<optimized out>)
    at /usr/include/c++/8/bits/shared_ptr_base.h:728
#11 0x00005555556092ba in std::__shared_ptr<CLI::App, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr (this=0x5555569f2670, __in_chrg=<optimized out>)
    at /usr/include/c++/8/bits/shared_ptr_base.h:1167
#12 0x00005555556092d6 in std::shared_ptr<CLI::App>::~shared_ptr (this=0x5555569f2670, __in_chrg=<optimized out>) at /usr/include/c++/8/bits/shared_ptr.h:103
#13 0x0000555555658536 in std::_Destroy<std::shared_ptr<CLI::App> > (__pointer=0x5555569f2670) at /usr/include/c++/8/bits/stl_construct.h:98
#14 0x000055555564f0ff in std::_Destroy_aux<false>::__destroy<std::shared_ptr<CLI::App>*> (__first=0x5555569f2670, __last=0x5555569f2690)
    at /usr/include/c++/8/bits/stl_construct.h:108
#15 0x0000555555643244 in std::_Destroy<std::shared_ptr<CLI::App>*> (__first=0x5555569f2670, __last=0x5555569f2690) at /usr/include/c++/8/bits/stl_construct.h:137
#16 0x000055555563331f in std::_Destroy<std::shared_ptr<CLI::App>*, std::shared_ptr<CLI::App> > (__first=0x5555569f2670, __last=0x5555569f2690)
    at /usr/include/c++/8/bits/stl_construct.h:206
#17 0x0000555555621735 in std::vector<std::shared_ptr<CLI::App>, std::allocator<std::shared_ptr<CLI::App> > >::~vector (this=0x7fffffffe3c8, __in_chrg=<optimized out>)
    at /usr/include/c++/8/bits/stl_vector.h:567
#18 0x0000555555611474 in CLI::App::~App (this=0x7fffffffe1f0, __in_chrg=<optimized out>) at /.../CLI11.hpp:3912
#19 0x00005555555ed045 in main (argc=4, argv=0x7fffffffe578) at /../main.cxx:478
@henryiii
Copy link
Collaborator

Can you share any surrounding code? Looks a bit like Apps are trying to be deleted twice. Is this a drop in replacement for 1.7, or have you started making 1.8 related changes?

@chenziliang
Copy link
Author

the code starts brand new and the the CLI11.hpp is a copy from the release page. The seg-fault issue is not always reproducible. The code snippet looks like below:

#include <CLI11.hpp>                                                            
#include <string>                                                               
                                                                                   
using namespace std;                                                               
                                                                                   
int main(int argc, char** argv) {                                                  
    CLI::App app{"my-ap;"};                                                        
    app.require_subcommand(1, 2);                                                  
                                                                                   
    CLI::App* cmd1 = app.add_subcommand("cmd1");                                   
    cmd1->require_option();                                                        
                                                                                   
    CLI::Option* i_flag = cmd1->add_flag("--list-i", "list interfaces");                                                                           
    CLI::Option* d_flag = cmd1->add_flag("--list-d", "list devices");              
                                                                                   
    CLI::App* cmd2 = app.add_subcommand("cmd2");                                   
    string conf_file;                                                              
    cmd2->add_option("--config", conf_file, "cmd2 configuration file")             
        ->required()                                                               
        ->check(CLI::ExistingFile);                                                
                                                                                   
    CLI11_PARSE(app, argc, argv);                                                  
                                                                                                                                                  
    if (*cmd1) {                                                                   
        if (*i_flag) {                                                             
            // do something                                            
        } else if (*d_flag) {                                                      
           // do something                                              
        }                                                                          
        return 0;                                                                  
    } 
   
    if (*cmd2) {                                                                
        // do something                                           
    }                                                                           
    return 0; 
}        

@phlptp
Copy link
Collaborator

phlptp commented Jun 20, 2019

what is the code around line 478?, just want to make sure that is the end of the main function, not somewhere in the middle.

@henryiii
Copy link
Collaborator

I'm at a workshop at NYU and didn't bring my computer (not intentionally), so can't check yet, will be high priority when I get back. Have you triggered it with the code snippet above? What platform are you on? Linux gcc?

@henryiii
Copy link
Collaborator

You are not storing any subcommands in smart pointers, are you? Just making sure. They are internally in smart pointers and get deleted for you. Just a thought.

@chenziliang
Copy link
Author

  1. It is gcc8 in Linux
  2. No i didn't store any subcommand in smart porters. The code i posted is exactly the structure i have in my production code.
  3. I run the code in my env, but it doesn't trigger any seg-fault.
  4. My current workaround is new CLI::App in main to let it just leak, it will be gc by OS when my main process is gone anyway :)

@henryiii
Copy link
Collaborator

henryiii commented Jun 20, 2019

Ouch. I’d like to find out what is happening so you don’t have to leave the App leaking.

Can you stick a msg in the destructor of App (include the name, since subcommands are Apps) and see if it runs twice when not leaked?

I have one idea I’ll check when I can. Are you doing anything else “interesting” with subcommands the the real code?

@chenziliang
Copy link
Author

Thanks. I will do it when available. No, I don’t do anything fancy related to subcommand. The code I show here is exactly the structure and usage in my prod code

@chenziliang
Copy link
Author

This is probably related to my application in which there is memory overrun problem elsewhere. Will keep monitoring if the crash happens again. Thanks !

@henryiii
Copy link
Collaborator

Let me know if it turns out to be related to CLI11!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants