Created
January 5, 2015 21:51
-
-
Save necto/152027a3c021fafd082c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
int nr; | |
CriuVethPair **a, *p; | |
p = malloc(sizeof(*p)); | |
if (!p) | |
goto er; | |
criu_veth_pair__init(p); | |
p->if_in = strdup(in); | |
if (!p->if_in) | |
goto er_p; | |
p->if_out = strdup(out); | |
if (!p->if_out) | |
goto er_i; | |
nr = opts->n_veths + 1; | |
a = realloc(opts->veths, nr * sizeof(p)); | |
if (!a) | |
goto er_o; | |
a[nr - 1] = p; | |
opts->veths = a; | |
opts->n_veths = nr; | |
return 0; | |
er_o: | |
free(p->if_out); | |
er_i: | |
free(p->if_in); | |
er_p: | |
free(p); | |
er: | |
return -ENOMEM; | |
} | |
// ---vs--- | |
{ | |
vector<shared_ptr<CriuVethPair>> a = opts->veths; | |
try { | |
shared_ptr<CriuVethPair> p = new CruiVethPair; //throws if failed to allocate | |
// constructor calls everything else: criu_veth_pair__init(p); | |
a.push(p); //throws if failed to fit a new element. (reallocates automatically) | |
opts->n_veths = a.size(); | |
return 0; | |
} catch (...) { | |
return -ENOMEM; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment