Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Isolating and multiply instantiating a C library in-process

Tags:

c++

c

ipc

We have a C library (.lib windows & .a linux) that only allows creation of a singleton and that also doesn't shut down properly (memory leaked and threads left alive) having been once instantiated.

Rewriting it and hunting down the bugs aside, is there a simple way to isolate this kind of misbehaving code in-process such that the singleton restriction can be removed, and the unclean tidyup can be sandboxed?

I am mainly interested in any in-process options, if indeed there are any. A seperate process would obviously solve it, but would incur an architectural overhead to allow remote control of the library unless there are very low impact solutions for that (it has a wide API, so maintaining a lot of glue is not particularly attractive).

like image 338
idij Avatar asked Aug 17 '11 13:08

idij


1 Answers

Sorry, but there is no simple way to do this. Sandboxing badly behaving libraries is commonly done using separate processes, which you already suggested yourself. An IPC tool like Protocol Buffers might help in defining and implementing the IPC protocol.

like image 192
Fred Foo Avatar answered Oct 16 '22 23:10

Fred Foo