-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add list objects in a pool #12
Comments
Hi, Thank you, I created a branch wip-list-objects to test the code. (https://github.com/ksperis/node-rados/tree/wip-list-objects) |
I think obj_name is leaked here. Who's responsible for freeing obj_name? Could probably NanBufferUse to hand off the buffer to V8. |
NanNew (obj_name) isn't it enough to hand off the buffer ? |
NanNew creates a copy. For buffers you can use NanBufferUse that tells V8 it should take ownership of the buffer. However after re-reading the code I realize obj_name is a pointer to some allocation inside h_ctx and probably freed by librados when calling rados_objects_list_close. |
Hi, I need a list function about specified pool, and I have added this function at my local for test. Could someone could help review it and let it be support function? Thanks in advance~
[at rados.h]
...
class Ioctx : public node::ObjectWrap {
...
static NAN_METHOD(aio_objects_list);
}
[at rados.cc]
...
define ENOENT 2
NAN_METHOD(Ioctx::aio_objects_list) {
NanScope();
if (args.Length() < 1 ||
!args[0]->IsString()) {
return NanThrowError("Bad argument.");
}
Ioctx* obj = ObjectWrap::Unwrap(args.This());
if ( !obj->require_created() ) NanReturnNull();
rados_list_ctx_t h_ctx;
//Start listing objects in a pool.
int err = rados_objects_list_open(obj->ioctx, &h_ctx);
if (err < 0) {
return NanThrowError("open list failed.");
}
Local ret_list = NanNew();
uint32_t array_id = 0;
//Get the next object name and locator in the pool.
while(0 <= err) {
const char *obj_name;
err = rados_objects_list_next(h_ctx, &obj_name, NULL);
if (err == 0) {
ret_list->Set(array_id, NanNew(obj_name));
array_id++;
}
}
rados_objects_list_close(h_ctx);
if (err < 0 && err != -ENOENT) {
return NanThrowError("list_next failed.");
}
NanReturnValue(ret_list);
}
The text was updated successfully, but these errors were encountered: